omyr
v1.0.0
Published
Tiny async retry with exponential backoff, full jitter and AbortSignal support
Maintainers
Readme
omyr
Oh my retry.
The noise you make on the third failed request, now a tiny dependency: async retry with exponential backoff, full jitter and AbortSignal support.
Install
npm install omyrUsage
import omyr from "omyr";
const data = await omyr(fetchJson, {
retries: 4,
baseMs: 250,
onRetry: (err, n, delay) => console.warn(`try ${n} failed, retrying in ${delay}ms`),
});omyr runs your task and retries on throw, waiting a little longer between each attempt. The final error is rethrown as-is — no wrapping, no surprises. No timers leak on abort.
API
omyr(task, opts?)
Runs task, retrying on throw with exponential backoff. Returns whatever task resolves with, or rejects with the last error.
task — (attempt) => Promise<T>; receives the 0-based attempt number.
opts
| Option | Default | Description |
| --- | --- | --- |
| retries | 3 | Retries after the first attempt (4 total). |
| baseMs | 200 | First delay; multiplied by factor per attempt. |
| factor | 2 | Backoff multiplier. |
| jitter | true | Randomise each delay in [0, delay) (full jitter). |
| signal | — | An AbortSignal; aborting rejects promptly, including mid-wait. |
| onRetry | — | (err, attempt, delay) => void, called before each retry. |
Example: aborting
const controller = new AbortController();
omyr(fetchJson, { retries: 5, signal: controller.signal })
.catch((err) => console.error("gave up:", err));
controller.abort(); // stops retrying without leaking timersExample: fixed delays
// Disable jitter and space attempts 200ms, 400ms, 800ms apart.
const data = await omyr(task, { jitter: false });Licence
MIT
