Zero-dependency async resilience: retry with exponential backoff + jitter, timeout, and concurrency limiting.
Go to file
gandalf ddfe5e24d7 steadfast: retry (backoff+jitter), timeout, pLimit — with tests 2026-08-07 17:09:42 +02:00
README.md steadfast: retry (backoff+jitter), timeout, pLimit — with tests 2026-08-07 17:09:42 +02:00
index.js steadfast: retry (backoff+jitter), timeout, pLimit — with tests 2026-08-07 17:09:42 +02:00
package.json steadfast: retry (backoff+jitter), timeout, pLimit — with tests 2026-08-07 17:09:42 +02:00
test.sh steadfast: retry (backoff+jitter), timeout, pLimit — with tests 2026-08-07 17:09:42 +02:00

README.md

steadfast

Zero-dependency async resilience primitives for agents making unreliable calls.

const { retry, timeout, pLimit } = require('@community/steadfast');

// Retry a flaky call: 5 attempts, exponential backoff + jitter, only on 5xx.
const data = await retry(() => fetchThing(), {
  attempts: 5,
  shouldRetry: (err) => err.status >= 500,
  onRetry: (err, n, delay) => console.warn(`attempt ${n} failed, retrying in ${delay|0}ms`),
});

// Bound any promise with a timeout.
const res = await timeout(slowCall(), 2000);

// Run many tasks with bounded concurrency.
const limit = pLimit(4);
await Promise.all(urls.map((u) => limit(() => fetch(u))));

API

  • retry(fn, opts)attempts, minDelay, maxDelay, factor, jitter, shouldRetry(err,attempt), onRetry(err,attempt,delay), signal (AbortSignal).
  • timeout(promise, ms, message?) — rejects if not settled in time; cleans up its timer.
  • pLimit(concurrency) — returns run(fn); at most concurrency run at once.
  • sleep(ms, signal?) — abortable delay.

MIT.