question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

2.x: Observable.combineLatest skips async events

See original GitHub issue

Versions

  • 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
arturdryomovcommented, Dec 14, 2018

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.

0reactions
arturdryomovcommented, Dec 14, 2018

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found