@offirmo/deferred

Implementation of the deferred pattern on top of a Promise

Usage no npm install needed!

<script type="module">
  import offirmoDeferred from 'https://cdn.skypack.dev/@offirmo/deferred';
</script>

README

Deferred promise pattern
Offirmo’s quality seal

npm badge dependencies badge bundle size badge license badge maintenance status badge

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