How to convert rxJava2's Observable to Complet

2019-03-23 09:05发布

问题:

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

回答1:

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

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

Convert it back via toObservable if needed.



回答2:

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.



回答3:

Use Completable.merge(YourObservable()...



回答4:

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