1

I have asynchronous events that I need combining. I am constructing an array of N streams; each stream has an onValue function to process the returned data.

I have tried combining all of those streams into one onValues on top of the onValue, but it does not get called properly.

var streams = [] 
...
stream = Bacon.fromCallback .... 
stream.onValue...( )

streams.push(stream)

...
Bacon.onValues(streams, f() { .... } )

What would be the right way to have a function called back when EACH stream has a (unique) value... AND when everything is completed?

David Laberge
  • 15,435
  • 14
  • 53
  • 83
  • Sounds to me as if you rather want to use a Promise than a Stream here… – Bergi Sep 10 '14 at 18:39
  • @bergi how would you do it with a promise – David Laberge Sep 10 '14 at 18:56
  • Instead of `stream` it's `promise`, instead of `Bacon.fromCallback` you'll find something appropriate in the respective library that you use, instead of `onValue` you'd use `then`. And in the end you combine them by `Promise.all(promises).then(f)` – Bergi Sep 10 '14 at 18:58

1 Answers1

1

I would assume this does the job:

Bacon.combineAsArray(streams).onEnd(f)
Bergi
  • 630,263
  • 148
  • 957
  • 1,375