Async-retry

async-retry

Retrying made simple, easy, async.

async-retry is a promisified version of retry which makes things easier with the async-await syntax.

Get it: npm install async-retry

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 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: 500
})

Method signature:

1
retry(retrier : Function, opts : Object) => Promise

GIF FTW!

async-retry

Suggest a module

Comments