How to convert rxJava2's Observable to Complet

2019-03-23 08:44发布

I have Observable stream, and I want to convert it to Completable, how I could do that?

4条回答
啃猪蹄的小仙女
2楼-- · 2019-03-23 08:58

The fluent way is to use Observable.ignoreElements().

Observable.just(1, 2, 3)
.ignoreElements()

Convert it back via toObservable if needed.

查看更多
仙女界的扛把子
3楼-- · 2019-03-23 09:07

You can do something like below.

Observable<Integer> observable = Observable.just(1, 2, 3);
Completable completable = Completable.fromObservable(observable);

Like on an Observable, you will have to subscribe to the completable to start the asynchronous process that Observable wraps.

More details can be found here in the Java doc for the method.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-03-23 09:07

You could use Completable.fromObservable(xx). That is worked fine on my project.

查看更多
唯我独甜
5楼-- · 2019-03-23 09:09

Use Completable.merge(YourObservable()...

查看更多
登录 后发表回答