Socket
Book a DemoInstallSign in
Socket

delayed-promise-retry

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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.

latest
Source
npmnpm
Version
0.0.4
Version published
Weekly downloads
164
-45.33%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

async

FAQs

Package last updated on 01 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts