@johngw/async
TypeScript icon, indicating that this package has built-in type declarations

5.0.1 • Public • Published

@johngw/async

accumulateRace(AsyncIterator, number) => Promise<T[]>

Returns an array of results, that have been accumulated from an async interator, within an amount of milliseconds.

cancelablePromise(resolve, reject): Promise & { cancel: () => void }

Creates a promise that can be cancelled. Cancelling a promise is the same as rejecting it with CancelPromiseError.

mapP<T, R>(T[], (T, number) => Promise): Promise<R[]>

Shortcut for:

Promise.all(array.map(fn))

timeout(number = 0): Promise

Returns a promise that resolves in ms milliseconds.

defer(): { promise: Promise, resolve: (value: T | PromiseLike) => void }

Returns a promise and a resolve function that resolves the promise.

debounceP<Args extends unknown[], Return>(fn: (...args: Args) => Promise, ms: number) => typeof fn

Debounces fn to ms milliseconds. The debounced function will always return the last result (Promise<Return>).

detonate(number = 0, Error = TimeoutError): Promise

Returns a promise that rejects in ms milliseconds with the given Error.

detonateRace(Promise, number = 0, Error = TimeoutError): Promise

Returns a promise that resolves the given promise or rejects after ms milliseconds.

Readme

Keywords

none

Package Sidebar

Install

npm i @johngw/async

Weekly Downloads

37

Version

5.0.1

License

MIT

Unpacked Size

34.3 kB

Total Files

62

Last publish

Collaborators

  • johngeorgewright