Skip to content

Single.retry(When) #3548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TastyPi opened this issue Nov 27, 2015 · 3 comments
Closed

Single.retry(When) #3548

TastyPi opened this issue Nov 27, 2015 · 3 comments

Comments

@TastyPi
Copy link

TastyPi commented Nov 27, 2015

It would be nice if Single had retry operators like Observable.

Single<T> retry();

Single<T> retry(long count);

Single<T> retry(Func2<Integer, Throwable, Boolean> predicate);

Single<T> retryWhen(Func1<? super Observable<? extends Throwable>, ? extends Observable<?>>
    notificationHandler);

Single<T> retryWhen(
    Func1<? super Observable<? extends Throwable>, ? extends Observable<?>> notificationHandler,
    Scheduler scheduler);

The one I actually want is retryWhen but I imagine they'd have similar enough implementations to be fairly straightforward once you have one.

@passsy
Copy link
Contributor

passsy commented Dec 16, 2015

+1

@akarnokd
Copy link
Member

These are now implemented:

  • Single retry();
  • Single retry(long count);
  • Single retry(Func2<Integer, Throwable, Boolean> predicate);
  • Single retryWhen(Func1, ? extends Observable>
    notificationHandler);

The variant with the Scheduler isn't (and probably shouldn't even exist in the first place).

Let me know if they work out for you.

@Lechenko
Copy link

Lechenko commented Aug 14, 2020

Scheduler scheduler = Schedulers.from(Executors.newSingleThreadExecutor());
        Observable.fromCallable(()-> Observable.just(""))
                .flatMapSingle(v -> rest.send())
                .repeatWhen(completed -> completed.delay(10_000,TimeUnit.MILLISECONDS))
                .retryWhen(err -> err.delay(10_000,TimeUnit.MILLISECONDS))
                .subscribeOn(scheduler)
                .subscribe(new DisposableObserver<Boolean>() {
                    @Override
                    public void onNext(Boolean flag) {
                        Timber.e("onNext %s",flag);
                        if (flag){
                            dispose();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Timber.e("onError %s",e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        Timber.e("onComplete ");
                    }
                });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants