@susisu/promise-utils
v0.2.0
Published
Promise utilities
Downloads
2,453
Readme
@susisu/promise-utils
Promise utilities
# npm
npm i @susisu/promise-utils
# yarn
yarn add @susisu/promise-utils
# pnpm
pnpm add @susisu/promise-utils
Usage
triplet
Creates a triplet of a promise and its resolve and reject functions.
import { triplet } from "@susisu/promise-utils";
const [promise, resolve, reject] = triplet<number>();
resolve(42);
promise.then(res => {
console.log(res); // -> 42
});
attachActions
Attaches cancellable actions to a promise.
import { triplet, attachActions } from "@susisu/promise-utils";
const [promise, resolve, reject] = triplet<number>();
const [cancel] = attachActions(
promise,
res => { console.log(res); },
err => { console.log(err); }
);
cancel();
resolve(42); // no output