feature: most.create for nodejs style callbacks
See original GitHub issueNode has the below style of async API for their ecosystem. Seeing the most.create is going to be moved into its own project, can we get a simple/clean way to provide Node async functions to it to create a stream source? e.g. most.fromNodeCallback(myAsync)
function myAsync(val, cb) {
const err = null;
const result = "success";
// do something async
cb(err, result); // may be called once or multiple times
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
What are callbacks? - Node.js
js uses callbacks. A callback is a function called at the completion of a given task; this prevents any blocking, and allows other...
Read more >The callback pattern | Node.js Design Patterns
Callbacks are the materialization of the handlers of the reactor pattern and they are literally one of those imprints that give Node.js its...
Read more >nodeJs callbacks simple example - Stack Overflow
First we create a callback function that accepts two arguments err and data . One problem with asynchronous functions is that it becomes ......
Read more >Callback conventions in node.js, how and why - gists · GitHub
The following post explains the conventions that node.js uses for its callback patterns (referred to as Continuation-passing style) and how you should implement ......
Read more >JavaScript Callback Functions – What are Callbacks in JS and ...
Callbacks make sure that a function is not going to run before a task is completed but will run right after the task...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jadbox Now that @partially-applied has created mostify, and
@most/create
is available as an a la carte package, I feel like there are good solutions out there for now.So, I’ll close this, but please feel free to continue discussion here.
My first instinct is that it should be a separate package, e.g.
@most/node
or something fairly obvious like that, but I’m open to discussing it. Browser apps likely wouldn’t need it 90% of the time, so being able to add it to a project a la carte is appealing.Thoughts?
All most streams make the same guarantee: the function you pass to observe/forEach/reduce will not be called before observe/forEach/reduce returns. There are really two options for making that guarantee in
most.create
, either 1) wait for the stack to clear before calling the producer function passed tomost.create
, or 2) buffer events and propagate them after the stack clears.Originally, it did 1, which proved to be confusing for users, so we switched to 2.
Since node functions already are async (well, they should be anyway!), by their very nature they would not propagate an event before the stack clears. So, there is no need to a lot of the buffering gymnastics that
most.create
does … it’d just be adding overhead for no reason.There are a few other more minor factors. For example,
most.create
creates 3 closures to pass to the producer function. A node solution probably would only need 1. Also, becausemost.create
is a general purpose solution, it has to do more generalized error handling. That means it uses try/catch in several places, which prevents the VM from optimizing several functions.On the other hand, using Source/Sink directly is more “bare metal”. A node solution with Source/Sink would not need to do buffering, could create fewer closures, and could do error handling in a way that is more tailored to node style functions.