How to retry a consumed Observable?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 09:29:06

An option is to create Publisher, which emission is controlled by your button.

final PublishSubject<Object> retrySubject = PublishSubject.create();


service.excecuteLoginService(url,
            tokenModel,
            RetrofitManager.apiKey)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnError(throwable -> showButton())
            .retryWhen(observable -> observable.zipWith(retrySubject, (o, o2) -> o))
            .subscribeWith(result -> {}, error -> {});

Your button will just emit an item from the Subject:

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