GitXplorerGitXplorer
v

async-retry

public
1857 stars
53 forks
30 issues

Commits

List of commits on branch main.
Unverified
f2a5460e8abd7b5343cf67c4f1a30af623112a62

Bumped dependencies to the latest version

lleo committed 7 years ago
Unverified
2e3d9522054ca76ef8ba4e415bca13122f62e9ad

Switched to Yarn

lleo committed 7 years ago
Unverified
8b63aa41ce8d57d1adef32a57026bb89949500a0

Pass attempt number to onRetry (#41)

wwhitecrownclown committed 7 years ago
Unverified
a696d3670acd122b60f4ef6d76d999f54321939e

1.1.4

lleo committed 7 years ago
Unverified
13ee0bc98166d11afefa309bcf1aa3108c969a09

Added correct date to license

lleo committed 7 years ago
Unverified
f056d7381cdae8c2eefff0868d051d64bb04a334

Removed build flow (#38)

TTooTallNate committed 7 years ago

README

The README file for this repository.

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 async or not. In other words, it can be a function that returns a Promise or a value.
  • The supplied function receives two parameters
    1. A Function you can invoke to abort the retrying (bail)
    2. A Number identifying the attempt. The absolute first attempt (before any retries) is 1.
  • The opts are passed to node-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 1 to 2. Default is true.
    • onRetry: an optional Function that is invoked after a new retry is performed. It's passed the Error that triggered it as a parameter.

Authors