async.ts

Declarations
#

7 declarations

view source

AsyncStatus
#

create_deferred
#

async.ts view source

<T>(): Deferred<T>

Creates a object with a promise and its resolve/reject handlers.

returns

Deferred<T>

Deferred
#

async.ts view source

Deferred<T>

Creates a deferred object with a promise and its resolve/reject handlers.

generics

T

promise

type Promise<T>

resolve

type (value: T) => void

reject

type (reason: any) => void

is_promise
#

async.ts view source

(value: any): value is Promise<any>

Checks if value is a Promise.

value

type any

returns

boolean

map_concurrent
#

async.ts view source

<T, R>(items: T[], fn: (item: T, index: number) => Promise<R>, concurrency: number): Promise<R[]>

Maps over items with controlled concurrency, preserving input order.

items

array of items to process

type T[]

fn

async function to apply to each item

type (item: T, index: number) => Promise<R>

concurrency

maximum number of concurrent operations

type number

returns

Promise<R[]>

promise resolving to array of results in same order as input

examples

Example 1

map_concurrent_settled
#

async.ts view source

<T, R>(items: T[], fn: (item: T, index: number) => Promise<R>, concurrency: number): Promise<PromiseSettledResult<R>[]>

Like map_concurrent but collects all results/errors instead of failing fast. Returns an array of settlement objects matching the Promise.allSettled pattern.

items

array of items to process

type T[]

fn

async function to apply to each item

type (item: T, index: number) => Promise<R>

concurrency

maximum number of concurrent operations

type number

returns

Promise<PromiseSettledResult<R>[]>

promise resolving to array of PromiseSettledResult objects in input order

examples

Example 1

wait
#

async.ts view source

(duration?: number): Promise<void>

Waits for the given duration before resolving.

duration

type number
default 0

returns

Promise<void>

Imported by
#