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

rtry

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rtry

rtry allows you to easily add promise retry logic to classes, and functions

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

rtry Build Status

what?

rtry allows you to easily add promise retry logic to classes, and methods

install

npm install --save rtry

decorator usage

you can define a universal decorator like this

import rtry from 'rtry';

class DecoratorExample {
    @rtry({retries: 10, verbose: true})
    static canRetry () {
        if (Math.random() < 0.5) {
            throw new Error('random error');
        }
    }
}
DecoratorExample.canRetry();

function usage

import rtry from 'rtry';

let functionExample = () => {
    const rand = Math.random();

    if (rand < 0.5) {
        throw new Error('random error');
    }

    return rand;
};

let functionExampleRetry = rtry({retries: 10, verbose: true}, functionExample);

functionExampleRetry().then(result => {
    console.log(result);
});

options

  • beforeRetry (function / async function)
  • retries (number)
  • delay (number / function / async function)
  • verbose (boolean)

you can handle error logging in a custom way as well

const debug = requre('debug')('example');

@rtry({beforeRetry: ({retry, error}) => debug(error.stack)})
class Example {
    static canError () {
        throw new Error('abcd');
    }
}

FAQs

Package last updated on 28 Feb 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