@ende/async

ende add jsr:@ende/async

Version 2026.10.15 on JSR.

Provide helpers with asynchronous tasks, like delay, debounce, retry, or pooledMap.

import { delay } from "@ende/async/delay";

await delay(100); // waits for 100 milliseconds

Modules

Exports

  • abortable — Make a Promise abortable with the given signal.
  • allKeyed — Resolves all values in a record of promises in parallel, returning a promise that resolves to a record with the same keys and resolved values.
  • allSettledKeyed — Resolves all values in a record of promises in parallel, returning a promise that resolves to a record with the same keys and PromiseSettledResult objects as values.
  • Channel — An async channel for communicating between concurrent tasks with optional bounded buffering and backpressure.
  • ChannelClosedError — Error thrown when operating on a closed channel. When thrown from Channel.send, the `value` property carries the unsent value for recovery.
  • ChannelOptions — Options for the Channel constructor.
  • ChannelReceiveOptions — Options for Channel.receive.
  • ChannelReceiveResult — Result of a non-blocking Channel.tryReceive call. Discriminate on the `state` field:
  • ChannelSendOptions — Options for Channel.send.
  • deadline — Create a promise which will be rejected with DOMException when a given delay is exceeded.
  • DeadlineOptions — Options for deadline.
  • debounce — Creates a debounced function that delays the given `func` by a given `wait` time in milliseconds. If the method is called again before the timeout expires, the previous call will be aborted.
  • DebouncedFunction — A debounced function whose execution is delayed by a given `wait` time in milliseconds. If the function is called again before the timeout expires, the previous call will be aborted.
  • DebounceOptions — Options for debounce.
  • delay — Resolve a Promise after a given amount of milliseconds.
  • DelayOptions — Options for delay.
  • Lazy — A lazy value that is initialized at most once, with built-in deduplication of concurrent callers. Prevents the common race where two concurrent `get()` calls both trigger the initializer; only one initialization runs and all callers share the same promise.
  • LazyGetOptions — Options for Lazy.prototype.get.
  • MuxAsyncIterator — Multiplexes multiple async iterators into a single stream. It currently makes an assumption that the final result (the value returned and not yielded from the iterator) does not matter; if there is any result, it is discarded.
  • poll — Repeatedly calls a function until a condition is met, then returns the result.
  • PollOptions — Options for poll.
  • pooledMap — pooledMap transforms values from an (async) iterable into another async iterable. The transforms are done concurrently, with a max concurrency defined by the poolLimit.
  • PromiseRecord — A record type where values can be promise-like (thenables) or plain values.
  • retry — Calls the given (possibly asynchronous) function up to `maxAttempts` times. Retries as long as the given function throws. If the attempts are exhausted, throws a RetryError with `cause` set to the inner exception.
  • RetryError — Error thrown in retry once the maximum number of failed attempts has been reached.
  • RetryOptions — Options for retry.
  • SettledRecord — A record type where values are PromiseSettledResult objects.
  • tee — Branches the given async iterable into the `n` branches.
  • Tuple — Utility for representing n-tuple. Used in tee.
  • TupleOf — Utility for representing n-tuple of. Used in Tuple.