GitXplorerGitXplorer
v

async-retry

public
1857 stars
53 forks
30 issues

Commits

List of commits on branch main.
Verified
b08d512d05b388f5a02f18bdfc6f905827444ece

1.3.1

llucleray committed 5 years ago
Unverified
9b05890c9b120f70c751085b22b1a5aa505ba3bb

[FIX]: Make parameter opts optional again. (#66)

yyeldiRium committed 5 years ago
Verified
75cb6e0ab9737d861e1628e41d9caaf8c2af2a79

1.3.0

llucleray committed 5 years ago
Unverified
f64b83de88b6018796ff84a099d28ed7007e83c1

[Feature] Default `randomize` to true (#49)

wwhitecrownclown committed 6 years ago
Unverified
17eb4d23a01dec5d69f905d4da35f02566b05a13

1.2.3

lleo committed 6 years ago
Verified
95a55595c66095d826e9101b7348100a6b45ee72

Replace Circle CI with Now CI (#46)

lleo committed 6 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