Reputation: 2657
I have a Completable
created like this:
public Completable doCalulations() {
return Completable.fromCallable(() -> {
//some calculations
})
.andThen(/*Here I want to sequentially execute another Completable*/);
}
After first Completable
calls onComplete
I want to execute sequentially another Completable
based on some condition:
if (condition.check()) {
return someCalculation(); //returns Completable
} else {
return anotherCalculation(); //returns Completable
}
How can I do this?
Upvotes: 1
Views: 1410
Reputation: 69997
Use defer
:
public Completable doCalulations() {
return Completable.fromCallable(() -> {
//some calculations
})
.andThen(
Completable.defer(() -> {
if (condition.check()) {
return someCalculation(); //returns Completable
} else {
return anotherCalculation(); //returns Completable
}
})
);
}
Upvotes: 4