Utilities
retry()
Section titled “retry()”Configurable retry with fixed or exponential backoff. Skips on AbortError so cancellation propagates immediately.
import { retry } from 'sysopkit';
// Fixed backoff (default)await retry( async () => { await sh('curl -s http://api/health'); }, { attempts: 3, delay: 1000 },);
// Exponential backoffawait retry( async () => { await sh('curl -s http://api/health'); }, { attempts: 5, delay: 500, backoff: 'exponential', maxDelay: 30_000 },);
// With retryOn predicateawait retry( async () => { // only retry on specific errors }, { attempts: 3, retryOn: (err) => err instanceof TimeoutError },);timeout()
Section titled “timeout()”Wraps a function with an AbortController-based timer. Throws TimeoutError if the function exceeds the limit.
import { timeout } from 'sysopkit';
await timeout(async () => { await sh('long-running-command');}, 30_000);sleep()
Section titled “sleep()”Abort-aware delay. Rejects with signal.reason on cancellation.
import { sleep } from 'sysopkit';
await sleep(5000); // wait 5 seconds