1

Given two Bacon.Buses I need to combine their respective values. However, the second bus is vastly more "productive" (about 1:200), the first bus is also slower and its first value is severely delayed, e.g. fetched via XHR or something similar. Because of this the first value in the first bus is emitted after the first "batch" has already gone through the second bus. Thus Bacon.onValues(bus1, bus2, f(b1, b2)) doesn't work, neither does bus1.sampledBy(b2, f(b1, b2)) for the same reasons.

I assume I need a way to buffer my second bus and release it as soon as the first bus emits a value. Probably I need something like pausable stream mentioned in issue #300, but maybe I'm missing something very obvious here.

So how do I delay the second bus until a value appears on the first one?

Nikolai Prokoschenko
  • 8,465
  • 11
  • 58
  • 97
  • What kind of semantics are you looking for? Zip maybe? That will combine first A with first B, second A with second B etc. – raimohanska Apr 02 '14 at 07:37
  • Hmm. Rather `(a[0], b[0]), (a[0], b[1]), (a[0], b[2]), ...` until `a[1]` appears, then `(a[1], b[n]), (a[1], b[n+1]), ...` etc. It's actually a simple `combineAsArray`, but it seems I can't get it to actually wait for `a[0]` to appear, so I get something like `(a[0], b[50]), (a[1], b[51]), ...` – Nikolai Prokoschenko Apr 02 '14 at 09:38
  • @Phae7rae: I don't know whether SO is acting weird, but it seems you have given an answer and then deleted it. Was it a mistake? Would appreciate your input! – Nikolai Prokoschenko Apr 03 '14 at 13:58

1 Answers1

0

combineAsArray() seems to do the job just fine

Check this demo:

http://codepen.io/turbohz/pen/jFxqw

TurboHz
  • 2,146
  • 2
  • 16
  • 14
  • No, it doesn't, but thanks for the example -- I've modified it to show the problem. Look at http://codepen.io/anon/pen/urfJs -- since the second stream starts five seconds later than the first one, `combineAsArray` misses all the events from the first one, so that the output counter starts at "5:0". – Nikolai Prokoschenko May 02 '14 at 11:05
  • 1
    I converted the streams to properties before combining,and then it seems to work as expected:http://codepen.io/anon/pen/eBita – TurboHz May 02 '14 at 11:33
  • And I broke it again :) http://codepen.io/anon/pen/IwApr -- I've removed initial property value, since that's exactly the case (e.g. AJAX requests). – Nikolai Prokoschenko May 02 '14 at 11:38
  • I'll need to re-read your question, because I think I'm not really getting what you're trying to achieve – TurboHz May 02 '14 at 12:14
  • I'd like to buffer values on one stream until the other stream becomes active, `combineAsArray` after that. – Nikolai Prokoschenko May 02 '14 at 13:19