https://github.com/adametherzlab/retry-ts
Typed retry with exponential backoff, jitter, and AbortController support
https://github.com/adametherzlab/retry-ts
async backoff bun resilience retry typescript
Last synced: 9 days ago
JSON representation
Typed retry with exponential backoff, jitter, and AbortController support
- Host: GitHub
- URL: https://github.com/adametherzlab/retry-ts
- Owner: AdametherzLab
- License: mit
- Created: 2026-03-05T12:11:49.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-03-09T06:38:16.000Z (about 1 month ago)
- Last Synced: 2026-03-09T11:40:30.958Z (about 1 month ago)
- Topics: async, backoff, bun, resilience, retry, typescript
- Language: TypeScript
- Size: 23.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# retry-ts 🔄
[](https://github.com/AdametherzLab/retry-ts/actions) [](https://www.typescriptlang.org/) [](LICENSE)
**Type-Safe Retries with Custom Backoff Strategies, Jitter, and Abort Support**
## Features
- **Custom backoff strategies**: exponential, linear, fixed, or bring your own
- Configurable jitter strategies (none, full, equal, decorrelated)
- Timeout and AbortController support
- Custom retry conditions via `shouldRetry`
- Error filtering with `retryOn` and `abortOn` for granular control
- Zero dependencies — pure TypeScript/ESM
## Installation
bash
bun add @adametherzlab/retry-ts
## Quick Start
import { retry } from '@adametherzlab/retry-ts';
const fetchData = async (signal: AbortSignal) => {
const response = await fetch('https://api.example.com/data', { signal });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
};
// Basic retry with exponential backoff and no jitter
try(fetchData, {
maxAttempts: 3,
baseDelayMs: 200,
});
// Use linear backoff with decorrelated jitter
const data = await retry(fetchData, {
maxAttempts: 5,
baseDelayMs: 100,
maxDelayMs: 5000,
backoffStrategy: 'linear',
jitterStrategy: 'decorrelated'
});
console.log('Data fetched:', data);
// Retry only on specific errors
class NetworkError extends Error {}
const flakyOperation = async () => {
if (Math.random() < 0.7) {
throw new NetworkError('Connection lost');
}
return 'Success!';
};
try(flakyOperation, {
maxAttempts: 5,
retryOn: NetworkError, // Only retry if NetworkError is thrown
baseDelayMs: 50,
jitterStrategy: 'full'
});
// Abort retries if a specific error occurs
class AuthError extends Error {}
const authProtectedOperation = async () => {
if (Math.random() < 0.5) {
throw new NetworkError('Connection lost');
} else if (Math.random() < 0.2) {
throw new AuthError('Unauthorized');
}
return 'Authorized data!';
};
try(authProtectedOperation, {
maxAttempts: 5,
retryOn: NetworkError,
abortOn: AuthError, // Stop immediately if AuthError is thrown
baseDelayMs: 50,
jitterStrategy: 'equal'
});