Closed betalb closed 3 years ago
Without having investigated, the issue is probably less about synchronous emit and more about the circular dependency between a
& b
.
yes, there is a cycle, but it is not infinite and is actually done to illustrate an issue
Here is another more dirty example that produces the same result
let e;
Kefir.stream((emitter) => { e = emitter; })
.debounce(100)
.withHandler((emitter, event) => {
if (event.type === 'value' && event.value === 1) {
e.emit(2);
}
emitter.emitEvent(event)
}).log();
e.emit(1);
Actually I created PR that should highlight where the issues seems to be. And there are similar problems in buffer-by
, buffer-while-by
(I just wanted to create cleaner test case before creating separate ticket)
This is documented behaviour:
Although documentation might be more clear probably. My idea was back then is that synchronous events is not a use case I wanted to support well in the library in general.
@rpominov I'm not following documentation quote, for me it sound like a different case, which I never faced 🙂
This issue is not with the fact that some value is emitted without being debounced, but completely wrong value (null
) being emitted
Also I've provided 2nd example that doesn't use properties and here is 1st example without using properties either
const a = Kefir.pool();
const b = a.debounce(100).spy();
a.plug(b.filter((val) => val === 1).map(() => 2));
a.plug(Kefir.stream(emitter => { emitter.emit(1) }));
a.observe();
@rpominov The issue isn't that it's emitted synchronously (it actually isn't, according to the issue description), but that the second event is dropped.
Ah, right, sorry
Hey guys, @betalb opened a PR fixing this, do you think we could merge their PR?
@bpinto Done. Let me get a release out this weekend.
If you will try to do synchronous emit in debounced observable incorrect sequence of events will be produced
i.e.
Expected output
Actual output