Wrapping flaky network, DB or queue calls so transient failures recover automatically instead of surfacing as errors.
Overview
Resilience for flaky calls: retry() with exponential backoff + full jitter (shouldRetry/onRetry/AbortSignal), withTimeout() that cancels slow work, and a CircuitBreaker that fails fast while a dependency is down then recovers. Wrap any fetch / DB / queue call.
Install
$ npm install @lacspace/retry
Quick example
@lacspace/retryts
retry(() => fetch(url), { retries: 4 })
Returns Promise<T>
Tips
`retry(fn, { retries, factor })` uses exponential backoff with full jitter to avoid thundering-herd retries.
Use `shouldRetry` to retry only on transient errors (e.g. 5xx / network), not on 4xx.
Wrap slow calls in `withTimeout()` and protect a failing dependency with `CircuitBreaker`.
Zero-dependency and isomorphic — safe to import on the server, in the browser, on the edge and in React Native. It tree-shakes, so you only ship what you import.
Watch out for
Only retry idempotent operations — retrying a non-idempotent POST can double-charge. Pair with @lacspace/idempotency.