Namespace: async

Classes

Type Aliases

JobHandler

Ƭ JobHandler<In, Out>: (job: In) => Promise<Out>

Job handler callback for processing a single job.

Type parameters

Name
In
Out

Type declaration

▸ (job): Promise<Out>

Parameters
Name Type
job In
Returns

Promise<Out>


ResolvablePromise

Ƭ ResolvablePromise<T>: Promise<T> & Resolvable<T>

ResolvablePromise intersection type: Promise with added resolve and reject functions.

Type parameters

Name Type
T void

Functions

batch

batch<T>(batch, concurrency?): Promise<T[]>

Call a batch of async functions with an optional concurrency limit.

Type parameters

Name
T

Parameters

Name Type Default value Description
batch () => Promise<T>[] undefined List of functions to call
concurrency number Infinity Optional max limit for concurrent calls

Returns

Promise<T[]>


defer

defer<T>(promise): Promise<T>

Defer a promise rejection until the next await call. This will prevent the promise from throwing an UnhandledPromiseRejectionWarning in case it rejects before the async code has reached the await.

Type parameters

Name
T

Parameters

Name Type Description
promise Promise<T> Promise to defer

Returns

Promise<T>


resolvable

resolvable<T>(): ResolvablePromise<T>

Returns a new ResolvablePromise that can be resolved or rejected “from the outside” with promise.resolve or promise.reject.

Type parameters

Name Type
T void

Returns

ResolvablePromise<T>


wait

wait(time): Promise<void>

Just like setTimeout but can be awaited: await wait(1000)

Parameters

Name Type Description
time number Time to wait in milliseconds

Returns

Promise<void>