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

Can onRetry handle async functions? #43

Open
amaury1093 opened this issue Jun 28, 2018 · 4 comments
Open

Can onRetry handle async functions? #43

amaury1093 opened this issue Jun 28, 2018 · 4 comments

Comments

@amaury1093
Copy link

amaury1093 commented Jun 28, 2018

I have this situation where I download the file, and want to delete this file (async operation) if the downloaded file is corrupted and needs retry.

    return retry(
      async (_, attempt) => {
        await downloadFileFromInternet();
      },
      {
        onRetry: err => {
         // It happens that downloaded file has an error
         // I want to delete the downloaded corrupted file
         await fs.unlink(pathToCorruptedFile);
        },
        retries: 3
      }
    );

Is it possible to have async-retry retry the next attempt only once the onRetry resolves (if the return value is a Promise)?

@BenJackGill
Copy link

BenJackGill commented May 25, 2022

Any update on this?

I added an async modifier to the onRetry callback but my await functions are not awaited.

To follow on from your example:

    return retry(
      async (_, attempt) => {
        await downloadFileFromInternet();
      },
      {
        onRetry: async (err) => {
         // It happens that downloaded file has an error
         // I want to delete the downloaded corrupted file
         await fs.unlink(pathToCorruptedFile); // This does not wait
        },
        retries: 3
      }
    );

@tvld
Copy link

tvld commented Jun 21, 2022

Actually, are you sure? In my case await in onRetry() seems to work just fine

@BenJackGill
Copy link

When I was facing this problem I was fairly sure that was the problem. I now use p-retry instead.

@JiriKovar
Copy link

I'm sure that the onRetry() is not awaited... It seems we will need to drop the usage of this package because for this reason as there is no workaround and its easier then rewriting everythin we need to use in onRetry to a synchronous implementation.

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

4 participants