delayed-promise-retry

0.0.4 • Public • Published

Welcome to delayed-promise-retry 👋

Version Documentation Maintenance License: MIT Npm Downloads

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

🤝 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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.4
    7,357
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.4
    7,357
  • 0.0.3
    0
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i delayed-promise-retry

Weekly Downloads

7,357

Version

0.0.4

License

MIT

Unpacked Size

7.5 kB

Total Files

10

Last publish

Collaborators

  • publiosilva