1.0.2 • Published 7 years ago
promise-endeavour v1.0.2
Promise Endeavour
Retry failed promises.
Table of Contents
Usage
const promiseEndeavour = require('promise-endeavour');
async function getDogs() {
const response = await fetch('https://dog.ceo/api/breeds/list/all');
return response.json();
}
const retries = [100, 500, 1000];
function retry(error, attempt) {
return retries[attempt - 1] || false;
}
promiseEndeavour(getDogs, retry)
.then(dogs => console.log(dogs));API
promiseEndeavour(promiseFactory, onFailure) => promiseRetryingFactory
promiseFactory is a function that returns a promise. onFailure is a
function that controls the retry logic.
onFailure(error, attempt) => boolean | number
onFailure will be called when the promise returned by promiseFactory rejects.
error will be the rejection value, and attempt is a number representing
how many times we've attempted so far. If it fails once, the attempt will be 1.
The return value of onFailure controls the retry logic. To stop retrying return
false. To retry immediately return true. To retry after a delay, return a
number in milliseconds.
Changelog
1.0.2 - Fix types field in package.json
Contribute
See the contribute file!
PRs accepted.