New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

retry-simple

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

retry-simple

Simplify async retries in JavaScript and TypeScript — supports exponential backoff, jitter, timeouts, and custom retry conditions.

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

retry-simple

A lightweight and flexible retry utility for asynchronous operations — built for Node.js and TypeScript.

npm version npm downloads license

✨ Features

  • 🔁 Retry logic with configurable attempts
  • ⏱️ Per-attempt timeout
  • 📈 Exponential backoff support
  • 🎲 Jitter (±20%) to avoid retry storms
  • 🚦 Max delay cap for controlled exponential growth
  • 🧩 Custom retry conditions (shouldRetry)
  • 🪝 Retry hook (onRetry) after each failed attempt

🚀 Installation

npm install retry-simple

or using yarn:

yarn add retry-simple

🚀 Usage

🟦 TypeScript Example

import { retry } from "retry-simple";

let attempt = 0;

async function unstableOperation() {
  attempt++;
  if (attempt < 3) throw new Error(`Fail attempt ${attempt}`);
  return "✅ Success on attempt " + attempt;
}

const result = await retry(unstableOperation, {
  retries: 5,
  delay: 500,
  backoff: true,
  jitter: true,
  onRetry: (err, attempt) =>
    console.log(`Attempt ${attempt} failed: ${(err as Error).message}`)
});

console.log(result);

🟨 JavaScript Example (CommonJS)

const { retry } = require("retry-simple");

let attempt = 0;

async function unstableOperation() {
  attempt++;
  if (attempt < 3) throw new Error(`Fail attempt ${attempt}`);
  return "✅ Success on attempt " + attempt;
}

retry(unstableOperation, {
  retries: 5,
  delay: 500,
  backoff: true,
  jitter: true,
  onRetry: (err, attempt) =>
    console.log(`Attempt ${attempt} failed: ${err.message}`)
})
  .then(console.log)
  .catch(console.error);

Output

Attempt 1 failed: Fail attempt 1
Attempt 2 failed: Fail attempt 2
✅ Success on attempt 3

➕ See more advanced examples in MORE_EXAMPLES.md

⚙️ API Reference

retry(fn, options?)

Runs an asynchronous function with automatic retry logic.

ParameterTypeRequiredDescription
fn() => Promise<T>The async function to execute.
optionsRetryOptionsOptional configuration (see below).

⚙️ Retry Options

OptionTypeDefaultDescription
retriesnumber3Maximum number of retry attempts (excluding the first try).
delaynumber1000Initial delay between retries in milliseconds.
backoffbooleanfalseDoubles the delay after each failed attempt (exponential backoff).
jitterbooleanfalseAdds ±20% randomness to delay to prevent retry storms.
maxDelaynumberundefinedMaximum allowed delay between retries.
timeoutnumberundefinedTimeout for each individual attempt (ms).
onRetry(error: unknown, attempt: number) => voidundefinedCallback executed after each failed attempt before retrying.
shouldRetry(error: unknown, attempt: number) => boolean() => trueCustom logic to decide whether to continue retrying based on the error or attempt number.

🏷️ Changelog

v0.0.2

Initial functional release

  • Added full retry configuration support:
    • retries, delay, backoff, jitter, maxDelay, timeout, onRetry, shouldRetry
  • Added detailed documentation and usage guide

v0.0.1

Initial placeholder release

  • Reserved package name and project setup

🌟 Support

If you like this utility, consider giving it a ⭐ on GitHub!
Feedback and contributions are always welcome 🙌

© 2025 Theresa Lau — Released under the MIT License

Keywords

retry

FAQs

Package last updated on 19 Nov 2025

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