Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x Observable#concatMapEager doesn't always preserve order #4981

Closed
ansman opened this issue Jan 11, 2017 · 2 comments
Closed

2.x Observable#concatMapEager doesn't always preserve order #4981

ansman opened this issue Jan 11, 2017 · 2 comments

Comments

@ansman
Copy link
Contributor

ansman commented Jan 11, 2017

Sample code (using RxJava 2.0.4):

Observable.just(1, 2, 3, 4, 5)
        .concatMapEager(i -> {
            System.out.println("Processing " + i);
            return i == 3 ? Observable.just(i) : Observable
                    .just(i)
                    .delay(1, TimeUnit.MILLISECONDS, Schedulers.io());
        })
        .observeOn(Schedulers.io())
        .subscribe(i -> System.out.println("Value: " + i));

Expected output:

Processing 1
Processing 2
Processing 3
Processing 4
Processing 5
Value: 1
Value: 2
Value: 3
Value: 4
Value: 5

Actual output:

Processing 1
Processing 2
Processing 3
Processing 4
Processing 5
Value: 3
Value: 1
Value: 2
Value: 4
Value: 5

As you can see the order is incorrect. This is due to the fact that the item 3 is mapped to a Callable source which won't wait for the previous observables.

@ansman ansman changed the title 2.x concatMapEager doesn't always preserve order 2.x Observable#concatMapEager doesn't always preserve order Jan 11, 2017
@akarnokd akarnokd added this to the 2.0 backlog milestone Jan 11, 2017
@akarnokd
Copy link
Member

Thanks for the feedback. This is indeed a bug with Observable.concatMapEager(). Flowable works properly.

I'll post a fix shortly. A workaround is to use just(i).hide() to break the bad/false internal optimization.

@akarnokd
Copy link
Member

Closing via #4982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants