Is there something in bacon.js that converts back to a node callback, like Q does with it's node adapters? https://github.com/kriskowal/q#adapting-node
Asked
Active
Viewed 108 times
0
-
What do you mean by "back to a node callback", can you show an example of how you'd like to use this? Where exactly does Q do this; it only offers methods to convert nodeback-methods to promise methods? – Bergi Apr 10 '14 at 15:49
1 Answers
1
If I understand correctly, you want to invoke node-style callback when there is value on stream ?
stream.onValue(function(val) {
callback(null, val);
}).mapError(callback);
There is no convenience function in Bacon to do that (or I didn't noticed that), but it's so small piece of code, that you can do it by yourself. Note that I have used onValue, because you need at least one consumer, however if you are consuming stream elsewhere, you can do it simply like this:
stream.map(callback.bind(null, null)).mapError(callback);
Edit:
If you need to support multiple arguments to the callback that are delivered in the array from the stream, it would look like this:
stream.onValue(function(values) {
callback.apply(null, null, values);
});

FredyC
- 3,999
- 4
- 30
- 38