RxJava: How to multicast a Completable?

大兔子大兔子 提交于 2019-12-11 05:24:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!