Skip to main content

@std/async@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)

Classes

c

Error thrown when Deadline times out.

c

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.

  • add(iterable: AsyncIterable<T>): void

    Add an async iterable to the stream.

  • iterate(): AsyncIterableIterator<T>

    Returns an async iterator of the stream.

c
RetryError(
cause: unknown,
attempts: number
)

Error thrown in retry once the maximum number of failed attempts has been reached.

Functions

f
abortable<T>(
p: Promise<T> | AsyncIterable<T>,
signal: AbortSignal
): Promise<T> | AsyncIterable<T>
2 overloads

Make Promise abortable with the given signal.

f
abortableAsyncIterable<T>(
p: AsyncIterable<T>,
signal: AbortSignal
): AsyncGenerator<T>

Make AsyncIterable abortable with the given signal.

f
abortablePromise<T>(
p: Promise<T>,
signal: AbortSignal
): Promise<T>

Make Promise abortable with the given signal.

f
deadline<T>(
p: Promise<T>,
ms: number,
options?: DeadlineOptions
): Promise<T>

Create a promise which will be rejected with DeadlineError when a given delay is exceeded.

f
debounce<T extends Array<any>>(
fn: (
this: DebouncedFunction<T>,
...args: T
) => void
,
wait: number
): DebouncedFunction<T>

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.

f
delay(
ms: number,
options?: DelayOptions
): Promise<void>

Resolve a Promise after a given amount of milliseconds.

f
pooledMap<T, R>(
poolLimit: number,
array: Iterable<T> | AsyncIterable<T>,
iteratorFn: (data: T) => Promise<R>
): AsyncIterableIterator<R>

pooledMap transforms values from an (async) iterable into another async iterable. The transforms are done concurrently, with a max concurrency defined by the poolLimit.

f
retry<T>(
fn: (() => Promise<T>) | (() => T),
opts?: RetryOptions
): Promise<T>

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.

f
tee<T, N extends number = 2>(
iterable: AsyncIterable<T>,
n?: N
): Tuple<AsyncIterable<T>, N>

Branches the given async iterable into the n branches.

Interfaces

I

Options for Deadline.

  • signal: AbortSignal

    Signal used to abort the deadline.

I

A debounced function that will be delayed by a given wait time in milliseconds. If the method is called again before the timeout expires, the previous call will be aborted.

  • clear(): void

    Clears the debounce timeout and omits calling the debounced function.

  • flush(): void

    Clears the debounce timeout and calls the debounced function immediately.

  • pending: boolean

    Returns a boolean whether a debounce call is pending or not.

I

Options for delay.

  • persistent: boolean

    Indicates whether the process should continue to run as long as the timer exists.

  • signal: AbortSignal

    Signal used to abort the delay.

I

Options for retry.

  • jitter: number

    Amount of jitter to introduce to the time between attempts. This is 1 for full jitter by default.

  • maxAttempts: number

    The maximum amount of attempts until failure.

  • maxTimeout: number

    The maximum milliseconds between attempts.

  • minTimeout: number

    The initial and minimum amount of milliseconds between attempts.

  • multiplier: number

    How much to backoff after each retry.

Type Aliases

T
Tuple<T, N extends number> = N extends N ? number extends N ? T[] : TupleOf<T, N, []> : never

Utility for representing n-tuple. Used in tee.

T
TupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N ? R : TupleOf<T, N, [T, ...R]>

Utility for representing n-tuple of. Used in Tuple.

Variables

v
ERROR_WHILE_MAPPING_MESSAGE: "Threw while mapping."

Error message emitted from the thrown error while mapping.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/async

Import symbol

import * as mod from "@std/async";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/async";