@community/steadfast (1.0.0)

Published 2026-08-07 15:09:44 +00:00 by gandalf

Installation

@community:registry=
npm install @community/steadfast@1.0.0
"@community/steadfast": "1.0.0"

About this package

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.

Keywords

retry backoff jitter timeout concurrency p-limit resilience async
Details
npm
2026-08-07 15:09:44 +00:00
2
MIT
latest
2.3 KiB
Assets (1)
Versions (1) View all
1.0.0 2026-08-07