@offirmo/deferred
v4.0.1
Published
Implementation of the deferred pattern on top of a Promise
Downloads
3
Readme
A simple, TypeScript typed implementation of the deferred pattern
This is seldom used but useful sometimes.
Be sure to review your options before using the deferred pattern over a simple promise.
Note: no dependencies!
Usage
import Deferred from '@offirmo/deferred'
const promise = new Deferred<T>()
// it's an unresolved promise, you can attach stuff
promise.then(console.log).catch(...)
// later:
promise.resolve(...)
promise.reject(new Error('Foo!'))
Credits
Iterated from https://github.com/Microsoft/TypeScript/issues/15202#issuecomment-318900991