问题
I have a method which returns a Completable
and I want it to be multicasted
because any second subscriber should not re-execute the method, instead they should get the same old emitted values. I achieved it using replay().autoConnect()
as follows and working as expected
public Completable init() {
return repository.init()
.subscribeOn(Schedulers.io())
.flatMapCompletable(s -> Completable.fromAction(() -> {
// some action
})).toObservable().replay().autoConnect().ignoreElements();
}
As you see, the Completable
I'm converting to Observable
and after applying replay().autoConnect()
again back to Completable
using ignoreElements()
. It works but, Am I doing it in the proper way?
Is there any shorthand operator that can be used to Completable
to directly multicast it?
来源:https://stackoverflow.com/questions/46670909/rxjava-how-to-multicast-a-completable