Skip to content

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

Closed
@ansman

Description

@ansman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions