Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

promise-retry

Package Overview
Dependencies
2
Maintainers
2
Versions
17
Issues
File Explorer

Advanced tools

promise-retry

Retries a function that returns a promise, leveraging the power of the retry module.

    2.0.1latest

Version published
Maintainers
2
Weekly downloads
6,904,336
decreased by-19.83%

Weekly downloads

Readme

Source

node-promise-retry

NPM version Downloads Build Status Dependency status Dev Dependency status Greenkeeper badge

Retries a function that returns a promise, leveraging the power of the retry module to the promises world.

There's already some modules that are able to retry functions that return promises but they were rather difficult to use or do not offer an easy way to do conditional retries.

Installation

$ npm install promise-retry

Usage

promiseRetry(fn, [options])

Calls fn until the returned promise ends up fulfilled or rejected with an error different than a retry error.
The options argument is an object which maps to the retry module options:

  • retries: The maximum amount of times to retry the operation. Default is 10.
  • factor: The exponential factor to use. Default is 2.
  • minTimeout: The number of milliseconds before starting the first retry. Default is 1000.
  • maxTimeout: The maximum number of milliseconds between two retries. Default is Infinity.
  • randomize: Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.

The fn function will receive a retry function as its first argument that should be called with an error whenever you want to retry fn. The retry function will always throw an error.
If there are retries left, it will throw a special retry error that will be handled internally to call fn again. If there are no retries left, it will throw the actual error passed to it.

If you prefer, you can pass the options first using the alternative function signature promiseRetry([options], fn).

Example

var promiseRetry = require('promise-retry'); // Simple example promiseRetry(function (retry, number) { console.log('attempt number', number); return doSomething() .catch(retry); }) .then(function (value) { // .. }, function (err) { // .. }); // Conditional example promiseRetry(function (retry, number) { console.log('attempt number', number); return doSomething() .catch(function (err) { if (err.code === 'ETIMEDOUT') { retry(err); } throw err; }); }) .then(function (value) { // .. }, function (err) { // .. });

Tests

$ npm test

License

Released under the MIT License.

Keywords

FAQs

What is promise-retry?

Retries a function that returns a promise, leveraging the power of the retry module.

Is promise-retry popular?

The npm package promise-retry receives a total of 5,783,596 weekly downloads. As such, promise-retry popularity was classified as popular.

Is promise-retry well maintained?

We found that promise-retry demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 2 open source maintainers collaborating on the project.

Last updated on 14 Jun 2020

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc