如何在RxJava2中链接两个Completable [英] How to chain two Completable in RxJava2
问题描述
我有两个可完成的。我想做以下场景:
如果第一个Completable到达onComplete,继续第二个Completable。最终结果将是第二个可完成的完成。
I have two Completable. I would like to do following scenario: If first Completable gets to onComplete , continue with second Completable. The final results would be onComplete of second Completable.
当我有单个 getUserIdAlreadySavedInDevice()和Completable 时,我就是这样做的login():
This is how I do it when I have Single getUserIdAlreadySavedInDevice() and Completable login():
@Override
public Completable loginUserThatIsAlreadySavedInDevice(String password) {
return getUserIdAlreadySavedInDevice()
.flatMapCompletable(s -> login(password, s))
}
推荐答案
您正在寻找然后
运营商。
返回首先运行此Completable然后另一个可完成的Completable。
Returns a Completable that first runs this Completable and then the other completable.
firstCompletable
.andThen(secondCompletable)
一般来说,此运算符是 flattable
的替换可完成
:
In general, this operator is a "replacement" for a flatMap
on Completable
:
Completable andThen(CompletableSource next)
<T> Maybe<T> andThen(MaybeSource<T> next)
<T> Observable<T> andThen(ObservableSource<T> next)
<T> Flowable<T> andThen(Publisher<T> next)
<T> Single<T> andThen(SingleSource<T> next)
这篇关于如何在RxJava2中链接两个Completable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!