New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

retryify

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retryify

Wrap a function to retry on specific errors

latest
Source
npmnpm
Version
6.0.0
Version published
Weekly downloads
415
-23.99%
Maintainers
4
Weekly downloads
 
Created
Source

retryify NPM version Build Status Coverage Status Greenkeeper

Quickly and easily wrap functions to make them retry when they fail.

Installation

$ npm install retryify

Example

// create a new retryify wrapper with some options set.
const retryify = require('retryify')({
  retries: 5,
  timeout: 1000,
  factor: 2,
  errors: [RequestError, StatusCodeError],
  log: function(msg) { console.log(msg); },
});

// promisified request library
const request = require('request-promise');

// get will now retry each time it catches a RequestError or a
// StatusCodeError, it retries 5 times, or the request finally resolves
// successfully.
const get = retryify(function(url) {
  return request(url);
});

// or, add some custom options for this specific function
const post = retryify({
  retries: 10
}, function(url, data) {
  return request({
    uri: url,
    method: 'POST',
  });
});

// send the request, but retry if it fails.
get('http://google.com')
  .then(...)
  .catch(...);

retryify([options]) ⇒ function

Retry module setup function. Takes an options object that configures the default retry options.

Kind: global function
Returns: function - retryWrapper A decorator function that wraps a a function to turn it into a retry-enabled function.
Throws:

  • TypeError when function is passed instead of options object. To use retryify it first must be "constructed" by passing in an options object and the returned function is what is supposed to take the function to retry.
ParamTypeDefaultDescription
[options]Options{}Optional configuration object

retryify~retryWrapper([innerOptions], fn) ⇒ function

retryify function decorator. Allows configuration on a function by function basis.

Kind: inner method of retryify
Returns: function - The wrapped function.

ParamTypeDescription
[innerOptions]OptionsOptional configuration object. Same format as above.
fnfunctionThe function to wrap. Will retry the function if any matching errors are caught.

Options : Object

Kind: global typedef
Properties

NameTypeDefaultDescription
[options.retries]Number3Number of times to retry a wrapped function
[options.initialDelay]Number0Amount of time (ms) to wait before any function attempts
[options.timeout]Number300Amount of time (ms) to wait between retries
[options.factor]Number2The exponential factor to scale the timeout by every retry iteration. For example: with a factor of 2 and a timeout of 100 ms, the first retry will fire after 100 ms, the second after 200 ms, the third after 400 ms, etc.... The formula used to calculate the delay between each retry: timeout * Math.pow(factor, attempts)
[options.shouldRetry]function() => trueInvoked with the thrown error, retryify will retry if this method returns true.
[options.log]functionLogging function that takes a message as

Keywords

retryify

FAQs

Package last updated on 19 May 2022

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