delayed-promise-retry
v0.0.4
Published
A helper to execute a promise a certain number of times if it's throwing an exception, also inserting a delay between each attempt.
Downloads
327
Maintainers
Readme
Welcome to delayed-promise-retry 👋
A helper to execute a promise a certain number of times if it's throwing an exception, also inserting a delay between each attempt.
🏠 Homepage
Install
npm install delayed-promise-retry
yarn add delayed-promise-retry
Examples
Static delay
const { delayedPromiseRetry } = require('delayed-promise-retry');
(async () => {
const fn = async () => {
console.log('trying...');
throw new Error();
};
const retries = 3;
const retryDelay = 1000;
try {
await delayedPromiseRetry(fn, retries, retryDelay);
} catch(error) {
console.log(error);
}
})();
Custom delay
const { delayedPromiseRetry } = require('delayed-promise-retry');
(async () => {
const fn = async () => {
console.log('trying...');
throw new Error();
};
const retries = 3;
const retryDelay = (retryNumber) => retryNumber * 1000;
try {
await delayedPromiseRetry(fn, retries, retryDelay);
} catch(error) {
console.log(error);
}
})();
Exponential delay
const { delayedPromiseRetry, exponentialDelay } = require('delayed-promise-retry');
(async () => {
const fn = async () => {
console.log('trying...');
throw new Error();
};
const retries = 3;
try {
await delayedPromiseRetry(fn, retries, exponentialDelay);
} catch(error) {
console.log(error);
}
})();
Author
👤 Publio Blenilio
- Github: @publiosilva
- LinkedIn: @publio-blenilio-b97a2b130
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2021-present Publio Blenilio.
This project is MIT licensed.