Package Exports
- async-retry
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (async-retry) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
async-retry
Retrying made simple, easy, and async.
Usage
// Packages
const retry = require('async-retry');
const fetch = require('node-fetch');
await retry(
async (bail) => {
// if anything throws, we retry
const res = await fetch('https://google.com');
if (403 === res.status) {
// don't retry upon 403
bail(new Error('Unauthorized'));
return;
}
const data = await res.text();
return data.substr(0, 500);
},
{
retries: 5,
}
);API
retry(retrier : Function, opts : Object) => Promise- The supplied function can be
asyncor not. In other words, it can be a function that returns aPromiseor a value. - The supplied function receives two parameters
- A
Functionyou can invoke to abort the retrying (bail) - A
Numberidentifying the attempt. The absolute first attempt (before any retries) is1.
- A
- The
optsare passed tonode-retry. Read its docsretries: The maximum amount of times to retry the operation. Default is10.factor: The exponential factor to use. Default is2.minTimeout: The number of milliseconds before starting the first retry. Default is1000.maxTimeout: The maximum number of milliseconds between two retries. Default isInfinity.randomize: Randomizes the timeouts by multiplying with a factor between1to2. Default istrue.onRetry: an optionalFunctionthat is invoked after a new retry is performed. It's passed theErrorthat triggered it as a parameter.
Authors
- Guillermo Rauch (@rauchg) - Vercel
- Leo Lamprecht (@notquiteleo) - Vercel