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

async-retry-wrapper

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

async-retry-wrapper

Wrap the async function

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
increased by35.71%
Maintainers
1
Weekly downloads
 
Created
Source

async-retry-wrapper

Documentation

Retry wrapper for async function.

Installation

$ npm install async-retry-wrapper

Javascript

const retryWrapper = require('async-retry-wrapper');

Typescript

import * as retryWrapper from 'async-retry-wrapper';

Usage

functions

An object consisting of an async function may be used. If it is not an async function, an error occurs.

const retryWrapper = require('async-retry-wrapper');

const functions = {
    logger: async () => {
        console.log('hello world!!');
    },
};

const wrappedFunctions = retryWrapper(functions);

option

You can also change the retry settings if you want(If there is no parameter, it operates as Default).

There are a total of three options.

  • options
    • count : How many times are you going to try again?
      • default: 1
    • interval: How often will you try again?, 0 means as quickly as possible.
      • default: 0 (milliseconds)
    • rule: When are you gonna stop trying again?, Only one parameter is error.
      • default: Retry if an error occurs

The example is an option to retry twice more at 100 ms intervals when the response status is not 500.

const retryWrapper = require('async-retry-wrapper');

const options = {
    count: 2,
    interval: 100, 
    // If the response status code is not 500, the retry will be stopped
    rule: err => err.status !== 500,
};

const wrappedFunctions = retryWrapper(someFunObject, options);

Demo

// import library
const retryWrapper = require('async-retry-wrapper');

// test object to be wrapped
const testFunctions = {
    logAndThrow: async () => {
        console.log('welcome');
        throw new Error('with occur error!');
    },
    log: async () => {
        console.log('hello world!');
    },
};

// wrapping object
const wrappedFunctions = retryWrapper(testFunctions);

// now you can see the function retries
wrappedFunctions['logAndThrow']();

License

MIT License

Keywords

FAQs

Package last updated on 02 Jan 2023

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