Skip to content
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

Does backoff-rxjs work for polling cases? #27

Open
wallaceicy06 opened this issue Sep 13, 2020 · 1 comment
Open

Does backoff-rxjs work for polling cases? #27

wallaceicy06 opened this issue Sep 13, 2020 · 1 comment

Comments

@wallaceicy06
Copy link

I came across your library which looks very helpful for my use case. I have an API that I would like to poll regularly, but backoff when errors occur. I'm trying to figure out how I can incorporate retryBackoff into that loop, but I'm seeing strange side effects where previous iterations are not being unsubscribed.

 this.poll$.pipe(
      switchMap(() => this.backend.callApi()),
      retryBackoff(
        {
          initialInterval: 500,
          maxInterval: 5000,
          resetOnSuccess: true,
        }
      ),
      tap(() => $poll.next())
    ).subscribe(
        response => console.log('successful response'),
        error => console.log(`error: ${error}`)
    );
@BehzadV
Copy link
Contributor

BehzadV commented Oct 2, 2021

I actually faced this problem before, and it took me numerous hours to finally figure it out. When retryBackOff decides to retry something, it retries THE WHOLE pipe, from the start (I believe this is the same behavior as RxJS, I'm not sure about it though).
Meaning that if you have 2000 observables in one pipeline and one of them fails, it starts retrying for the entire 2000 batch.
@wallaceicy06

In order to solve this, move your error-prone part into its own, inner pipe (A pipe inside a pipe) and place the retryBackOff inside the inner pipe.

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

No branches or pull requests

2 participants