@rocicorp/resolver
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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');
}

Package Sidebar

Install

npm i @rocicorp/resolver

Weekly Downloads

2,284

Version

1.0.1

License

Apache-2.0

Unpacked Size

13.8 kB

Total Files

5

Last publish

Collaborators

  • alexhking
  • darick
  • cesaraz1
  • grgbkr
  • aboodman
  • arv