@askrjs/askr/fx
Exports from the declarations published in @askrjs/askr. Signatures reflect the published artifact.
Exports
This entrypoint publishes 16 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.
debounceEventtype
debounceEvent: (ms: number, handler: EventListener, options?: { leading?: boolean; trailing?: boolean; }) => EventListener & { cancel(): void; flush(): void; }Wrap an event handler so rapid events are coalesced and delayed by ms.
idletype
idle: (fn: () => void, options?: { timeout?: number; }) => voidIdle — schedule low-priority work Useful for: background prep, non-urgent updates Falls back to setTimeout if requestIdleCallback unavailable
```ts
idle(() => prefetchData());
```oncetype
once: <T extends AnyFn>(fn: T) => TOnce — guard against double execution Useful for: init logic, event safety
```ts
const init = once(setup);
init(); // runs
init(); // does nothing
init(); // does nothing
```raftype
raf: <T extends AnyFn>(fn: T) => Scheduled<T> & { cancel(): void; }RAF — coalesce multiple updates into single frame Useful for: animation, layout work, render updates
```ts
const update = raf(render);
update(); // schedules on next frame
update(); // same frame, no duplicate
```rafEventtype
rafEvent: (handler: EventListener) => EventListener & { cancel(): void; }Wrap an event handler so it runs at most once per animation frame, using the latest event.
retrytype
retry: <T>(fn: () => Promise<T>, options?: RetryOptions) => Promise<T>Retry — attempt function with backoff Useful for: network calls, transient failures
```ts
const data = await retry(() => fetch(url), {
maxAttempts: 3,
delayMs: 100,
});
```RetryOptionstype
RetryOptions: anyOptions for {@link retry}.
maxAttempts- maxAttempts?: number;
delayMs- delayMs?: number;
backoff- backoff?: (attemptIndex: number) => number;
RetryOutcometype
RetryOutcome: | { status: 'success'; value: T }
| { status: 'error'; error: unknown }
| { status: 'cancelled' }Run fn, retrying with backoff on failure. Called from a mounted
component's task, watch callback, or event handler, pending attempts are
also cancelled when that component is cleaned up.
scheduleEventHandlertype
scheduleEventHandler: (handler: EventListener) => EventListenerscheduleIdletype
scheduleIdle: (fn: () => void, options?: { timeout?: number; }) => CancelFnSchedule fn during browser idle time; returns a cancel function. Called
from a mounted component's task, watch callback, or event handler, it is
also cancelled when that component is cleaned up.
scheduleRetrytype
scheduleRetry: <T>(fn: () => Promise<T>, options?: RetryOptions) => { cancel(): void; result: Promise<RetryOutcome<T>>; }scheduleTimeouttype
scheduleTimeout: (ms: number, fn: () => void) => CancelFnSchedule fn after ms; returns a cancel function. Called from a mounted
component's task, watch callback, or event handler, it is also cancelled
when that component is cleaned up.
throttletype
throttle: <T extends AnyFn>(fn: T, ms: number, options?: ThrottleOptions) => Scheduled<T> & { cancel(): void; }Throttle — rate-limit execution, keep first/last Useful for: scroll, mouse move, high-frequency events
```ts
const handleScroll = throttle(updateUI, 100);
window.addEventListener('scroll', handleScroll);
handleScroll.cancel();
```throttleEventtype
throttleEvent: (ms: number, handler: EventListener, options?: { leading?: boolean; trailing?: boolean; }) => EventListener & { cancel(): void; }Wrap an event handler so it runs at most once per ms interval.
ThrottleOptionstype
ThrottleOptions: anyOptions for {@link throttle}.
leading- leading?: boolean;
trailing- trailing?: boolean;
timeouttype
timeout: (ms: number) => Promise<void>Timeout — Promise-based delay Useful for: readable async code, waiting between retries
```ts
await timeout(300);
console.log('300ms later');
```