如何在RxJava2中链接两个Completable [英] How to chain two Completable in RxJava2

查看:164
本文介绍了如何在RxJava2中链接两个Completable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个可完成的。我想做以下场景:
如果第一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆