0.0.4 ā€¢ Published 3 years ago

delayed-promise-retry v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago