- Notifications
You must be signed in to change notification settings - Fork59
Retrying made simple, easy and async
License
NotificationsYou must be signed in to change notification settings
vercel/async-retry
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Retrying made simple, easy, and async.
// Packagesconstretry=require('async-retry');constfetch=require('node-fetch');awaitretry(async(bail)=>{// if anything throws, we retryconstres=awaitfetch('https://google.com');if(403===res.status){// don't retry upon 403bail(newError('Unauthorized'));return;}constdata=awaitres.text();returndata.substr(0,500);},{retries:5,});
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. Readits 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.
- Guillermo Rauch (@rauchg) -Vercel
- Leo Lamprecht (@notquiteleo) -Vercel
About
Retrying made simple, easy and async
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors11
Uh oh!
There was an error while loading.Please reload this page.