Does withStateMachine work with switching subscribers?
semmel opened this issue · comments
When I run the expectStreamEvents
unit tests on this simple withStateMachine
example the last 3 of 5 tests fail:
describe "propagates all values", ->
expectStreamEvents(
-> series(1, [1, 2, 3]).withStateMachine(0, (acc, evt) ->
if evt.isEnd
[undefined, [evt]]
else if evt.hasValue
[[], [evt, new Bacon.Next(evt.value * evt.value)]])
[1, 1, 2, 4, 3, 9])
The example is supposed to output the square alongside the value for each source value. Which works fine for a single subscriber, however:
propagates all values
(switching subscribers) / (switching subscribers with unsub) / (switching aggressively)
outputs expected values in order:
AssertionError: expected [ Array(3) ] to deeply equal [ Array(6) ]
+ expected - actual
[
1
+ 1
2
+ 4
3
+ 9
]
Well, this is no surprise really. Some streams are unstable in the face of switching subscribers on-the-fly. It means that the newly added subscriber doesn't get added between events occurings "simultaneously".
Because of this, some tests are flagged as unstable
or semiunstable
, as in here: https://github.com/baconjs/bacon.js/blob/master/spec/specs/bus.coffee#L45
So, it's known behavior. Not super nice, but you're not supposed to be doing this kind of subscriber-switching mid-event.
you're not supposed to be doing this kind of subscriber-switching mid-event.
Yes, I think so too.
I just was not sure how far to go with unit test situations when I wanted to introduce an additional stream combination function to Bacon. I.e. how bullet-proof it should be...
Thanks again for the fast reply!