npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ekaone/retry

v0.0.4

Published

Composable retry primitive with exponential backoff, jitter, and AbortSignal support

Readme

@ekaone/retry

Composable retry primitive with exponential backoff, jitter, and AbortSignal support.

Zero dependencies. Works in Node 18+, Bun, Deno, browsers, and edge runtimes.

Comparison — @ekaone/retry vs native fetch

See detailed comparison table here.

Retry

| Feature | @ekaone/retry | fetch | |---|---|---| | Automatic retry — Retries failed calls without manual loops | ✓ built-in | ✗ manual | | Max attempts — Hard cap on total number of tries | ✓ maxAttempts | ✗ none | | Exponential backoff — Delay grows as 2^attempt between retries | ✓ built-in | ✗ none | | Linear backoff — Delay grows linearly per attempt | ✓ built-in | ✗ none | | Fixed backoff — Constant delay between every attempt | ✓ built-in | ✗ none | | Jitter — Randomised delay to prevent thundering herd | ✓ full jitter | ✗ none | | Max delay cap — Upper bound on computed delay | ✓ 30s default | ✗ none |

Control

| Feature | @ekaone/retry | fetch | |---|---|---| | shouldRetry predicate — Selective retry on recoverable errors | ✓ per-error | ✗ none | | AbortSignal support — External cancellation mid-retry loop | ✓ built-in | ~ per-request only | | Total timeout — Cap on entire operation including delays | ✓ totalTimeoutMs | ✗ none | | onError hook — Callback fired after each failed attempt | ✓ per-attempt | ✗ none |

Error Handling

| Feature | @ekaone/retry | fetch | |---|---|---| | RetryError with diagnostics — Attempts count, lastError, failure reason | ✓ RetryError | ✗ raw error | | Failure reason — exhausted / aborted / timeout / rejected | ✓ reason field | ✗ none |

Scope

| Feature | @ekaone/retry | fetch | |---|---|---| | Works with any async fn — DB calls, SDK calls, agent turns | ✓ any Promise | ✗ HTTP only | | Works with Anthropic SDKanthropic.messages.create() | ✓ yes | ✗ no | | Works with native fetch — Can wrap fetch() calls too | ✓ yes | ✓ yes |

Runtime & Package

| Feature | @ekaone/retry | fetch | |---|---|---| | Zero dependencies | ✓ zero | ✓ native | | Node / Browser / Edge / Bun | ✓ universal | ✓ universal | | ESM + CJS dual output | ✓ tsup | N/A — native |

Install

npm install @ekaone/retry
# or
pnpm add @ekaone/retry

Usage

import { retry } from '@ekaone/retry'

// Basic
const data = await retry(() => fetch('https://api.example.com').then(r => r.json()))

// With options
const data = await retry(
  () => anthropic.messages.create({ model: 'claude-opus-4-5', ... }),
  {
    maxAttempts: 4,
    backoff: 'exponential',
    baseDelayMs: 200,
    jitter: true,
    shouldRetry: (error) => error?.status === 429,
    onError: (error, attempt) => console.warn(`Attempt ${attempt} failed`, error),
  }
)

API

retry(fn, options?)

| Option | Type | Default | Description | |---|---|---|---| | maxAttempts | number | 3 | Max attempts including the first call | | backoff | 'fixed' \| 'linear' \| 'exponential' | 'exponential' | Delay growth strategy | | baseDelayMs | number | 100 | Base delay in ms | | maxDelayMs | number | 30_000 | Upper cap on computed delay | | totalTimeoutMs | number | undefined | Cap on total elapsed time across all attempts | | jitter | boolean | false | Randomise delay to prevent thundering herd | | signal | AbortSignal | undefined | External cancellation | | shouldRetry | (error, attempt) => boolean \| undefined | undefined | Selective retry predicate | | onError | (error, attempt) => void | undefined | Per-attempt error hook |

RetryError

Thrown when all attempts are exhausted or retry is stopped.

import { retry, RetryError } from '@ekaone/retry'

try {
  await retry(() => unstable(), { maxAttempts: 3 })
} catch (err) {
  if (err instanceof RetryError) {
    console.log(err.attempts)   // number of attempts made
    console.log(err.lastError)  // original error from last attempt
    console.log(err.reason)     // 'exhausted' | 'aborted' | 'timeout' | 'rejected'
  }
}

Backoff Strategies

| Strategy | Delay formula | |---|---| | fixed | baseDelayMs every time | | linear | baseDelayMs × attempt | | exponential | baseDelayMs × 2^(attempt-1) |

All strategies are capped at maxDelayMs. Enable jitter: true to randomise between 0 and the computed value.

Integration with @ekaone/n-agent

n-agent is multi-agent conversation loop with human-in-the-loop support

import { createAgent } from '@ekaone/n-agent'
import { retry } from '@ekaone/retry'

const agent = createAgent({
  onError: async (error, ctx) => {
    await retry(() => ctx.replayTurn(), {
      maxAttempts: 3,
      backoff: 'exponential',
      jitter: true,
      signal: ctx.signal,
    })
    return 'skip'
  }
})

License

MIT © Eka Prasetia

Links


⭐ If this library helps you, please consider giving it a star on GitHub!