npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

retryify

v6.0.0

Published

Wrap a function to retry on specific errors

Downloads

12,376

Readme

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.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [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.

| Param | Type | Description | | --- | --- | --- | | [innerOptions] | Options | Optional configuration object. Same format as above. | | fn | function | The function to wrap. Will retry the function if any matching errors are caught. |

Options : Object

Kind: global typedef Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | [options.retries] | Number | 3 | Number of times to retry a wrapped function | | [options.initialDelay] | Number | 0 | Amount of time (ms) to wait before any function attempts | | [options.timeout] | Number | 300 | Amount of time (ms) to wait between retries | | [options.factor] | Number | 2 | The 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 | () => true | Invoked with the thrown error, retryify will retry if this method returns true. | | [options.log] | function | | Logging function that takes a message as |