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

retry-machine

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retry-machine

Retry Promises

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
430
decreased by-40.85%
Maintainers
0
Weekly downloads
 
Created
Source

Retry Machine

A simple and configurable utility for retrying promises with exponential backoff.

Installation

npm install retry-machine

or

yarn add retry-machine

Usage

retry-machine provides a flexible way to handle retries in your promises with support for exponential backoff and optional logging.

import { retry } from 'retry-machine';

async function run(attempt) {
  console.log(`Attempt ${attempt}`);
  if (Math.random() < 0.7) {
    throw new Error('Random failure');
  }
  return 'Success!';
}

async function failure(error, attemptsRemaining) {
  console.error(e);
}

const runner = retry({ max: 5, delay: 1000, factor: 2, maxDelay: 5000 }, failure);
await runner(run, 1);

Configuration options

  • max: The maximum number of attempts to retry the function. Default is 3.
  • delay: The initial delay between attempts, in milliseconds. Default is 1000.
  • factor: The exponential backoff factor. Default is 1.
  • logger: Optional logger to log failures and retry attempts.
  • maxDelay: The maximum delay between attempts, in milliseconds. Default is 30000 (30 seconds).

FAQs

Package last updated on 08 Nov 2024

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