RxJava - flatmap vs concatMap - why is ordering the same on subscription?

Viewed 2903

According to this thread conCatMap and flatmap only differ by the order in which items are emitted. So i did a test and created a simple stream of integers and wanted to see in what order they would be emitted. I made a small observable that would take in numbers in the range from 1-5 and multiple them by two. Easy.

Here is the code with flatmap:

myObservable.flatMap(new Func1<Integer, Observable<Integer>>() {
        @Override
        public Observable<Integer> call(Integer integer) {
            return Observable.just(integer * 2);
        }
    }).subscribe(new Observer<Integer>() {
        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(Integer integer) {
        Log.v("myapp","from flatMap:"+integer);
        }
    });

and the exact same code using concatMap:

myObservable.concatMap(new Func1<Integer, Observable<Integer>>() {
        @Override
        public Observable<Integer> call(Integer integer) {
            return Observable.just(integer * 2);
        }
    }).subscribe(new Observer<Integer>() {
        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(Integer integer) {
        Log.v("myapp","from concatmap:"+integer);
        }
    });

when i saw print out in the logs the ordering was the same for both, why ? I thought only concatMap will preserve order ?

1 Answers
Related