0.0.1 • Published 2 years ago

@prepared/promise-helpers v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@prepared/promise-helpers

A bunch of useful helpers for working with promises and async things

Installation

yarn add @prepared/promise-helpers

API

Completer

A Completer is a promise-like class that can be resolved or rejected imperatively.

Example

import { Completer } from "@prepared/promise-helpers";

// Completer accepts a generic type argument for the expected type to be
// returned when the completer's promise is resolved
const completer = new Completer<string>();

// Completers can be awaited, or you can use the `.then` method
// Completers also expose their promise (i.e. `completer.promise`)
completer.then((result) => {
  console.log(result);
});

// Calling `.resolve` will resolve the completer's promise
// In this case, we should see "Hello world" logged into the console
completer.resolve("Hello world");