An util to create promises and control their lifecycle from other scope. In other frameworks they usually call it "Deferred" too.

Example:

function sleep(ms) { const future = new Future() setTimeout(() => future.resolve(), ms) return future.promise }

async function main() { await sleep(1000) }

Type Parameters

  • T

Hierarchy

  • Future

Constructors

Properties

Constructors

Properties

promise: Promise<T>
reject: ((reason?: any) => void)

Type declaration

    • (reason?: any): void
    • Parameters

      • Optional reason: any

      Returns void

resolve: ((value: T | PromiseLike<T>) => void)

Type declaration

    • (value: T | PromiseLike<T>): void
    • Parameters

      • value: T | PromiseLike<T>

      Returns void

Generated using TypeDoc