0

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

Mattias Petter Johansson
  • 1,064
  • 1
  • 15
  • 32
  • 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 Answers1

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