@technical-1/retry
v1.0.0
Published
Generic backoff/retry wrappers keyed off the @technical-1/core retryable error contract
Downloads
33
Readme
@technical-1/retry
Generic async retry with exponential backoff and jitter. Retry-vs-terminal is
decided by the property contract from @technical-1/core (an error's
retryable === true), never by instanceof — safe across the dual ESM/CJS
package boundary.
import { withRetry } from "@technical-1/retry";
const html = await withRetry(() => fetchPage(url), { retries: 4 });withRetry(fn, opts?) calls fn(attempt) (1-based). On a thrown error it
retries iff opts.isRetryable(err) is true (default: err?.retryable === true)
and attempts remain; otherwise it rethrows. Delays grow
minDelayMs * factor^(attempt-1), capped at maxDelayMs, optionally jittered.
An AbortSignal cancels pending waits.
Requirements
This package's emitted TypeScript definitions reference AbortSignal (via
RetryOptions.signal), which is not part of the ES2022 lib. Your consumer
project must have @types/node installed as a devDependency (or include
"DOM" in your tsconfig lib):
npm install --save-dev @types/node
# or: pnpm add -D @types/node