Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@canastro/retry

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@canastro/retry

Retry strategy

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

build status npm version codecov XO code style

Retry

Naive implementation of a retry system.

Features

  • Max attempts
  • Add delay between retries
  • Callback to interrupt retries

Installation

npm install --save @canastro/retry

Usage

const retry = require('@canastro/retry');
const callback = (min, max) => () => (Math.random() * (max - min)) + min;

const isResolved = result => result > 19;

const options = {
    maxAttempts: 5,
    intervalTimeout: 1000
};

/**
 * This example will call a function that generates
 * a number between 2 and 20, and it will try for 5 times
 * to get a result higher then 19, having a delay
 * of 1000ms between each execution
 */
retry(callback(2, 20), options, isResolved)
    .then(result => {
        console.log('result: ', result);
    })
    .catch(() => {
        console.log('error');
    });

PS: Check sandbox for more examples, you can try them by running node sandbox/#filename#

Parameters

ParameterTypeDefaultDescription
callbackFunctionUser's function to be retried
optionsObject{}User's options
[options.maxAttempts]Number10Number of max attempts
[options.intervalTimeout]Number0msNumber of milliseconds to wait before retrying
isResolvedFunction() => trueFunction to be used as a stop condition

Returns

  • If a isResolved function is provided it will return a fulfilled promise when this returns true;
  • If no isResolved was given it will return true once the provided callback is correctly fulfilled;
  • It will return a rejected promise the max attempts was reached

Keywords

FAQs

Package last updated on 05 Mar 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc