u-promised
Promise based retry and backoff, bring your own Promises
npm install u-promised
API
retry(retries, fn)
- retries:
- number (0 - ...)
- -1 (retry forever)
- function (evaluated after each attempt; should return boolean)
- fn: function that returns a promise
const fetchGoogle = // retry forever - no catch // evalute retriesconst evalRetry = { let index = 0 return { if index === 5 return false index++ return true }}
backoff(delay, incrementor, retries, fn)
- delay: initial delay after first failure
- incrementor: increment to add to delay after each attempt
- retries:
- number (0 - ...)
- -1 (retry forever)
- function (evaluated after each attempt; should return boolean)
- fn: function that returns a promise
const fetchGoogle = const SECOND = 1000 // backoff forever // evaluate backoffconst evalBackoff = { let index = 0 return { if index === 5 return false index++ return true }}
Developing
There's really not much to this codebase. Just run npm test
. If you would like to contribute, please open an issue explaining what you would like to change/fix/add and make a pull request.