You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			|  | 2 years ago | |
|---|---|---|
| .. | ||
| lib | 2 years ago | |
| LICENSE.md | 2 years ago | |
| README.md | 2 years ago | |
| package.json | 2 years ago | |
		
			
				
				README.md
			
		
		
			
			
		
	
	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 docs- retries: The maximum amount of times to retry the operation. Default is- 10.
- factor: The exponential factor to use. Default is- 2.
- minTimeout: The number of milliseconds before starting the first retry. Default is- 1000.
- maxTimeout: The maximum number of milliseconds between two retries. Default is- Infinity.
- randomize: Randomizes the timeouts by multiplying with a factor between- 1to- 2. Default is- true.
- onRetry: an optional- Functionthat is invoked after a new retry is performed. It's passed the- Errorthat triggered it as a parameter.
 
Authors
- Guillermo Rauch (@rauchg) - Vercel
- Leo Lamprecht (@notquiteleo) - Vercel