Provides a simple Promise
resolver
npm install @rocicorp/resolver
resolver
returns a triplet of promise
, resolve
and reject
functions.
import {resolver} from '@rocicorp/resolver';
const {promise, resolve} = resolver<number>();
resolve(42);
await promise; // 42
reject
can be used to reject the promise.
import {resolver} from '@rocicorp/resolver';
const {promise, resolve, reject} = resolver<number, string>();
reject('fail');
try {
await promise;
// unreachable
} catch (e) {
assert(e === 'fail');
}