staltz / callbag-share

👜 Callbag operator that broadcasts a single source to multiple sinks
MIT License
22 stars 3 forks source link

Fix issue with synchronously requesting sink (such as forEach) #3

Closed Andarist closed 6 years ago

Andarist commented 6 years ago

Without this fix share crashes on forEach with:

TypeError: sourceTalkback is not a function

After my slight tweak this better reflect how things behave when there is only a single source-sink pair in regards to when the sink gets greeted

staltz commented 6 years ago

Hi @Andarist, thanks. Did you also run existing tests? sink(0,talkback) used to be the last operation, and then we just changed it to executed before, and now you're moving it back to be the last operation. I wonder if we're getting something wrong conceptually (overall). And wouldn't the sink(0,talkback) be called twice?

Andarist commented 6 years ago

Did you also run existing tests?

Yeah, made sure of that.

And wouldn't the sink(0,talkback) be called twice?

There is return statement preventing double calls

I wonder if we're getting something wrong conceptually (overall).

I believe new flow reflects normal situation better - before we were greeting sink & source in some order (one after the another). Now greeting sink is embeeded into the source greet.

Sink starts the subscription and gets the talkback back literally when the source decides to give it back - it's the same situation as with non-shared sources, just with additional layer of shared middleman. Previously sink got the talkback at arbitrary time, because it was the shared which gave it to the sink.

staltz commented 6 years ago

Okay, now I see it, I think I missed the return. Good that you ran the tests too (I should setup CI...). Thanks for the PR

staltz commented 6 years ago

v1.0.2