Mayoul
Mayoul

Reputation: 626

.concatMap() start the next Observable but previous one was not finished

I'm using RxJava on Android. I have a pretty quite simple piece of code here : Observable> observable =

Observable.create((ObservableOnSubscribe<Observable<Boolean>>) emitter1 -> {
                            emitter1.onNext(doSomething());
                            emitter1.onComplete();
                        }).concatMap(accessToken -> Observable.create((ObservableOnSubscribe<Observable<Boolean>>) emitter2 -> {                                                            
                            emitter2.onNext(doSomethingElse());
                            emitter2.onComplete();
                        }).observeOn(Schedulers.io()).subscribeOn(Schedulers.io()));

What I want to do =>

-> Start A
    -> A is processing
    -> A is ending
-> Start B
    -> B is processing
    -> B is ending

what I actually got :

-> Start A 
   -> A is processing
-> Start B
   -> B is processing
-> A is ending
-> B is ending 

But I thougt concatMap was waiting for the first observable to end before lauching the next one... ?

Upvotes: 0

Views: 294

Answers (1)

600
600

Reputation: 82

Please try like this :

Observable.create((ObservableOnSubscribe<Observable<Boolean>>) emitter1 -> {
                            emitter1.onNext(doSomething());
                            emitter1.onComplete();
                        }).concatMap(accessToken -> Observable.create((ObservableOnSubscribe<Observable<Boolean>>) emitter2 -> {                                                            
                            emitter2.onNext(doSomethingElse());
                            emitter2.onComplete();
                    })).observeOn(Schedulers.io()).subscribeOn(Schedulers.io());

Upvotes: -1

Related Questions