as-retryable-promise
Wraps a promise so that it can be retried
Usage
const asRetryablePromise = require("as-retryable-promise");
const fs = require("fs");
const fn = () => new Promise((resolve ,reject) => {
fs.readFile("./my-file.txt", (err, data) => {
if (err) return reject(err);
return resolve(data);
});
});
const options = {
maxRetries: 5,
timeout: 1000,
retryCondition: error => error.code === "EACCES",
};
const retryable = asRetryablePromise(fn, options);
retryable
.then(data => console.log(data))
.catch(err => console.error(err));