Skip to content

Utils

Utilities wrap individual functions or provide low-level async building blocks. Use them when you do not need a full control-flow primitive or executor.

import { memoize, compose, debounce } from "@vgerbot/async";
import { memoize } from "@vgerbot/async/utils";
API Description
memoize Caches results from an async function and returns cancellable handles.
cache / cachify Aliases for memoize.
asyncify Converts a synchronous function into a cancellable async function.
compose / seq Composes async functions right-to-left (compose) or left-to-right (seq).
constant Creates a cancellable handle resolving to a constant value.
debounce Debounces an async function.
throttle Throttles an async function.
once Ensures an async task runs once and reuses the result.
noop Empty function helper.
Defer Deferred promise primitive with external resolve/reject.
import { memoize } from "@vgerbot/async";
const getUser = memoize(async (id: number, token) => {
const response = await token.wrap(fetch(`/api/users/${id}`));
return response.json();
});
const handle = getUser(1);
const user = await handle.promise;