Non obvious behavior with `concat`, `Promise` and `EventEmitter`.
See original GitHub issueHello.
Using xstream
on a new project is my only experience with reactive programming so far. Therefore please excuse any obvious problems or mistakes.
I encountered a strange problem with this snippet:
concat(xs.fromPromise(somePromise), fromEvent(someEvent, 'test'));
My expectation was that concat
would buffer the test
events until the promise resolves (kind of like flattenSequentially
. But the events are dropped altogether. I wrote two tests to expose this problem: https://github.com/kaukas/xstream/commit/6e693896c72fda4143d607e2b3996797fb822d62. Could you please let me know if this is expected behavior?
Thank you!
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
ExpressJS apparent race condition between Promise and ...
The problem is coming from your internal call to busboy inside your handler. Rather than it executing and simply returning control to your ......
Read more >Ward Bell: Do Not Expect EventEmitter To Be Observable In ...
Promises only ever settle on one value, be it through resolution or rejection. So, in that case - in the case where you...
Read more >EventEmitter - Angular
Creates an instance of this class that can deliver events synchronously or asynchronously. This class is "final" and should not be extended. See...
Read more >A thenable should be synchronous? · Issue #5 · getify/native ...
Promise.resolve(2) would obviously be sync, so I'm not sure why the above should be forced to be async if you are handed a...
Read more >RxJS - Creation Operators - DEV Community
In this case we converted a promise to an observable. ... Concat unlike of combineLatest does not run all observables in concurrency, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, @staltz.
I’ve been playing further with this. I am not sure how
concat
should behave butflattenSequentially
is definitely not doing the right thing. Even in the case where the event is sent after the promise resolves the event is lost.I suspect the reason for the lost events is that the
fromEvents
stream is only activated after the previous stream (promise) completes. Therefore all prior events are lost. Instead thefromEvents
stream should be activated immediately onflattenSequentially
call so that all subsequent events could be buffered. At least this is my opinion.Thank you!
I’m implementing a version of buffering concat right now for my project.
This is a test case that shows the difference between the two versions of concat:
[0, 1, 2, 3, 4, 5]
instead of[0, 1, 2, 0, 1, 2]
The buffering concat behaves like
wheras xstream concat behaves like
As far as I can see xstream does what it documents. Hard to say what users expect.