1.0.1 • Published 7 months ago

async-retry-util v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Async Retry Utility

A lightweight utility to retry promise-based functions with customizable retry logic.

Installation

npm install async-retry-util

Usage

import { asyncRetry } from "async-retry-util";

async function unstableFunction() {
  if (Math.random() > 0.7) {
    return "Success!";
  }
  throw new Error("Failed attempt");
}

(async () => {
  const result = await asyncRetry(unstableFunction, {
    retries: 5,
    delay: 1000,
    onRetry: (attempt, error) => {
      console.log(`Attempt ${attempt} failed: ${error.message}`);
    },
  });
  console.log(result);
})();

Options

  • retries: Number of retry attempts (default: 3)..
  • delay: Delay between retries in milliseconds (default: 1000ms).
  • onRetry: Callback invoked on each retry with the attempt number and error.
1.0.1

7 months ago

1.0.0

7 months ago