Installation
$ npm install @pyriter/retry
$ pnpm add @pyriter/retry
$ yarn add @pyriter/retry
$ bun add @pyriter/retry
Overview
Wrap any async function in a retry policy with exponential backoff, jitter, and predicate-based stop conditions. Designed for transient network errors and rate-limited APIs.
- Exponential backoff with configurable jitter
- Stop predicates for non-retryable errors (4xx, etc.)
- AbortSignal support
- No dependencies
Usage
Retry a fetch call
import { retry } from '@pyriter/retry';
const data = await retry(
async () => {
const res = await fetch('https://api.example.com/data');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
},
{
attempts: 5,
backoffMs: 250,
jitter: true,
shouldRetry: (err) => !String(err).includes('404'),
},
); Keywords
retrybackoffresilienceTypeScript