@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.