Small wrapper for accepting cancellation tokens
Wraps your api methods and functions and make possible to pass a cancellable tokens.
Examples:
- If your function returns a
PromiseLike
object and you need to cancel it by passing cancellation token as a last argument, than you can usewrapFn
function.
; const yourFn = { ;}; const cancellableYourFn = ;const token = ;const result = ; // in a few moments you need to abort your actiontoken;
- If you don't want to mess up with every function and you have some API obejct with list of methods that returns a
PromiseLike
object and you need to cancel it by passing cancellation token as a last argument, than you can usewrap
function.
; const yourApi = { ; } { ; } { ; } const cancellableYourApi = ;const token = ;const result = cancellableYourApi; // in a few moments you need to abort your actiontoken;
For Node.js you can use npm package. You should install it:
npm i cancellation-wrapper
and import it in your file:
const wrapFn CancellationToken = ;