Skip to content

Creates a promise producer which controls the completion/rejection of the promise available through the .promise key.

License

Notifications You must be signed in to change notification settings

sevenwestmedia-labs/promise-completion-source

Repository files navigation

Promise completion source

Build Status NPM Package Greenkeeper badge

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

About

Creates a promise producer which controls the completion/rejection of the promise available through the .promise key.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published