Logic & Validation (async & is)
Resilient asynchronous control flow primitives and rigorous type/value validation guards.
Async Utilities (async)
.retry(fn, options?)
Executes an async function with automatic retry logic, exponential backoff, and error filtering.
const status = await __sys__.utils.async.retry(
async () => {
const res = await fetch("http://api.internal/");
if (res.status !== 200) throw new Error("Retryable error");
return res.status;
},
{ maxAttempts: 5, delay: 100, backoffFactor: 2 }
);.pool(items, fn, concurrency?)
Processes an array of items in parallel with a limited number of active promises (concurrency control).
await __sys__.utils.async.pool(imageUrls, downloadImage, 5); // Max 5 parallel downloads.timeout(fn, ms)
Wraps a promise with a maximum execution time. Throws an error if the timeout is reached.
const result = await __sys__.utils.async.timeout(() => heavyTask(), 2000);.attempt(fn)
Executes an async function and returns a discriminated result object. Simplifies flow control by avoiding global try/catch blocks.
const { ok, value, error } = await __sys__.utils.async.attempt(() => apiCall());.repeat(fn, ms, signal?)
Executes a function repeatedly with a fixed interval and automatic drift correction.
__sys__.utils.async.repeat(() => console.log("Tick"), 1000);.queue()
Creates a sequential task queue where jobs are executed one by one in the order they were added.
const q = __sys__.utils.async.queue();
q.add(async () => { /* job 1 */ });.memoize(fn, ttl?)
Caches the results of an async function. Supports request collapsing for identical concurrent calls.
const cachedFetch = __sys__.utils.async.memoize(fetchData, 5000);.sleep(ms, signal?)
Suspends execution for a specific duration. Supports AbortSignal for clean cancellation.
Repeated condition check
Burst prevention
Frequency limiting
Single execution guard
Validation Utilities (is)
Learn about core identity and functional helpers.
