# async-retry

> Retrying made simple, easy and async

Latest version **1.3.3** (published 2021-08-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-retry
pnpm add async-retry
yarn add async-retry
bun add async-retry
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2021-08-17 |
| First published | 2016-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/async-retry) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1919 |
| Maintainers | redacted-vercel, gkaragkiaouris, matheuss, igorklopov, leo, nkzawa, tootallnate, rauchg, timneutkens, javivelasco, iamevilrabbit, joecohens, quietshu, dav-is, juancampa, styfle, zeit-bot, lucleray, mglagola, andybitz, paulogdm, anatrajkovska, timer, umegaya, arzafran, ijjk, mfix22, lfades, rabaut, coetry, msweeneydev, williamli, ragojose, guybedford, paco, skllcrn, janicklas-ralph, atcastle, keanulee, spanicker, developit, housseindjirdeh, gmonaco, kikobeats, prateekbh, jkrems, jaredpalmer, gielcobben, chibicode, nazarenooviedo, samsisle, okbel, hankvercel, leerobinson, elsigh, julianbenegas, rizbizkits, raunofreiberg, sokra, cl3arglass, chriswdmr, ernestd, ismaelrumzan, jhoch, mitchellwright, mrmckeb, kuvos, creationix, aboodman, huozhi, cmvnk, arv, ktcarter, aspctub, padmaia, delba, catsaremlg, steventey, gsandhu, dbredvick |

## Links

- npm: https://www.npmjs.com/package/async-retry
- Repository: https://github.com/vercel/async-retry
- Homepage: https://github.com/vercel/async-retry#readme
- Issues: https://github.com/vercel/async-retry/issues
- npm.io page: https://npm.io/package/async-retry

## Dependencies (1)

- [retry](https://npm.io/package/retry.md) 0.13.1

## Recent versions

- 1.3.3 (latest) — 2021-08-17
- 1.3.1 — 2020-01-02
- 1.3.0 — 2020-01-02
- 1.2.3 — 2018-09-07
- 1.2.2 — 2018-09-07
- 1.2.1 — 2018-02-27
- 1.2.0 — 2018-02-27
- 1.1.4 — 2017-10-31
- 1.1.3 — 2017-07-05
- 1.1.2 — 2017-06-29
- 1.1.1 — 2017-06-03
- 1.1.0 — 2017-05-27
- 1.0.0 — 2017-05-27
- 0.3.0 — 2017-02-14
- 0.2.1 — 2016-05-30
- … 3 more at https://npm.io/package/async-retry/versions

## README

# async-retry

Retrying made simple, easy, and async.

## Usage

```js
// 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

```js
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](https://github.com/tim-kos/node-retry)
  - `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

- Guillermo Rauch ([@rauchg](https://twitter.com/rauchg)) - [Vercel](https://vercel.com)
- Leo Lamprecht ([@notquiteleo](https://twitter.com/notquiteleo)) - [Vercel](https://vercel.com)

---
_Source: https://npm.io/package/async-retry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
