promise-completion-source
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

/promise-completion-source/

    Package Sidebar

    Install

    npm i promise-completion-source

    Weekly Downloads

    671

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    285 kB

    Total Files

    17

    Last publish

    Collaborators

    • jakeginnivan