promise-completion-source

An object which controls completion of the .promise key

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
promise-completion-source
1.0.04 years ago4 years agoMinified + gzip package size for promise-completion-source in KB

Readme

Promise completion source
Build Status
Creates a promise producer which controls the completion/rejection of the promise available through the .promise key.

Example

import { PromiseCompletionSource } from 'promise-completion-source'

const promiseCompletionSource = new PromiseCompletionSource<Result>()

// This is a promise which can be awaited or passed around as a future
const promise = promiseCompletionSource.promise

// Then you can resolve/reject using the completion source
promiseCompletionSource.resolve(result)
// or
promiseCompletionSource.reject(new Error('Some error'))

// You can also check completion
const isPromiseCompleted = promiseCompletionSource.completed