2.x: Observable.combineLatest skips async events
See original GitHub issueVersions
- RxJava: 2.2.4
- RxAndroid: 2.1.0
Sample
val numberStream = mainThreadObservable // emits something
.map { 42 }
.logOnNext("source: number")
val booleanStream = ioThreadObservable // emits "true" at undefined moment
.startWith(false)
.logOnNext("source: boolean")
disposable += Observable
.combineLatest(
numberStream.logOnNext("combination: number"),
booleanStream.logOnNext("combination: boolean")
)
.logOnNext("combination")
.subscribe()
Output
Actual
13:06:44.654 I: [main] [source: boolean]: false
13:06:44.658 I: [main] [combination: number]: 42
13:06:44.660 I: [main] [combination: boolean]: false
13:06:44.661 I: [Rx-io-20] [source: boolean]: true
13:06:44.667 I: [main] [combination]: (42, false)
Expected
Everything as in Actual, but with this line in the end.
13:06:44.667 I: [main] [combination]: (42, true)
Thoughts
This does not happen all the time consistently though. Researching this behavior lead me to #5325. Is it true that Observable.combineLatest
is not guaranteed to process all onNext
events when dealing with multi-thread streams? What is the best practice in this scenario? Add observeOn(Schedulers.single())
to all streams in combineLatest
statement?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Chapter 9. Partitioning and combining observables - Rx.NET ...
Partitioning observables into groups of related notifications; Emitting chunks ... The CombineLatest operator combines the latest emitted values from each ...
Read more >Observable | RxJS API Document - ReactiveX
Creates an output Observable which sequentially emits all values from given Observable and then moves on to the next.
Read more >RxJS combineLatest without waiting for source observables to ...
2 Answers 2 · What I'm trying to do is for example, returning source1Data + source2Data , so I need each source data...
Read more >Part 1. RxJS: Better async programming | RxJS Fundamentals
Short answer: Observable is an object that represents a stream of data, to which we can subscribe to receive events/error notifications, ...
Read more >A glitch in combineLatest (and how to fix it!)
combineLatest holds the last values from all source streams (in the gif, the begin scenario was, limit = 8, offset = 2) ·...
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 Free
Top 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
Damn, the referred issue was created 4 hours ago. I swear it wasn’t on purpose 😉
I tend to disagree though. If I’m reading the article correctly André describes a case when both combinations are emitted. The sample I’ve attached above skips one entirely. I agree that the ordering might be lost due to async nature, but skipping the event looks like another issue.
Yep, it is never here. I’ll do my best ASAP, can be tricky due to multithreading though, but let’s see how it goes. Thanks!