@antoniovdlc/with-retry
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

with-retry

version issues downloads license

Retry asynchronous operations

Installation

This package is distributed via npm:

npm install @antoniovdlc/with-retry

Usage

You can use this library either as an ES module or a CommonJS package:

import withRetry from "@antoniovdlc/with-retry";

- or -

const withRetry = require("@antoniovdlc/with-retry");

You can then wrap any asynchronous function with withRetry and pass configuration options:

async function fn() { ... }

const result = await withRetry(fn, { ... });

Configuration

The configuration options are:

type RetryConfig = {
  maxAttempts: number;
  delay: number;
  maxDelay: number;
  backoffStrategy: RetryConfigBackoffStrategy;
  jitter: RetryConfigJitter;
  retryCondition: (error: Error) => boolean;
  onRetry: (error: Error, attempt: number) => void;
  onExhausted: (error: Error) => void;
  timeout: number;
};

Default values are set to:

{
  maxAttempts: 3,
  delay: 100,
  maxDelay: 1000,
  backoffStrategy: "constant",
  jitter: true,
  retryCondition: () => true,
  onRetry: () => {},
  onExhausted: () => {},
  timeout: 0,
}

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @antoniovdlc/with-retry

Weekly Downloads

34

Version

1.0.0

License

MIT

Unpacked Size

11.4 kB

Total Files

11

Last publish

Collaborators

  • antoniovdlc