@rocicorp/resolver
v1.0.2
Published
A simple promise resolver
Downloads
28,014
Readme
Resolver
Provides a simple Promise
resolver
Installation
npm install @rocicorp/resolver
Usage
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');
}