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

@yveskaufmann/retry

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yveskaufmann/retry

Utility for retrying promise based operation on certain situations.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
246
increased by2.93%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Node.js CI codecov

retry-utility

Utility for retrying promise based operation on certain situations.

  • Provides an imperative API.
  • Class decorators to mark async functions to be retryable Supports various backoff strategies: fixed, linear, exponential.

Installation

npm install @yveskaufmann/retry

Usage

The example below demonstrates how to annotate methods to mark them as retryable. When retryWhen return true the method is retried until it reaches the maxRetries limit.

When the retry limit is reached last result is returned or the last error is thrown.

When the limit is reached the last result, or the last thrown

NOTE: The Retryable annotation only works with methods that returning promises like async methods.

class Service {

  @Retryable({
    retryWhen: (result, err) => err != null,
    delay: Retry.Delays.linear(50),
    maxRetries: 3,
  })
  async retryOnAnyError() {
    // ...
  }

  @Retryable({
    retryWhen: (result, err) => err == null && result == false,
    delay: Retry.Delays.linear(50),
    maxRetries: 3,
  })
  async retryWhenFalseIsReturned() {
    return Math.random() < 0.6;
  }
}

This utility can also be used without annotating class methods.

 const response = await Retry.do({
  operation: () => client.get(...),
  retryWhen: (result, err) => HttpError.isTooManyRequest(err)
  maxRetries: 3,
  delay: Retry.Delays.constant(50),
});

API

The API is documented in the provided typescript definition file.

Keywords

FAQs

Package last updated on 15 Dec 2021

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