Skip to main content

cancellablePromise

function cancellablePromise<A, R>(callback, cleanup?): readonly [(...args) => Promise<void | Awaited<R>>, () => void];

Wrapping provided async callback to allow to resolve the async operation with cleanup when the cancel function is called

Type Parameters​

Type Parameter
A extends unknown[]
R

Parameters​

ParameterTypeDescription
callbackAsyncCallback<A, R>An async callback to execute
cleanup?Cleanup<R>A cleanup callback to execute when the provided async callback is canceled

Returns​

readonly [(...args) => Promise<void | Awaited<R>>, () => void]