Skip to main content

Home > flowp > Future

Future class

Future is a resolve-later Promise, you can resolve it any time after a future is created.

this feature is stable and is guaranteed to not have breaking change before v1.0.0

Signature:

export declare class Future<T = unknown> extends Promise<T> 

Extends: Promise<T>

Example

const future = new Future<number>()
// somewhere
const count = await future
// elsewhere, and the future becomes `fullfilled`
future.resolve(count)

Constructors

ConstructorModifiersDescription
(constructor)()Constructs a new instance of the Future class

Properties

PropertyModifiersTypeDescription
_reject(error: unknown) => void
_resolve(value: T | PromiseLike<T>) => void
[Symbol.species]staticPromiseConstructor
fulfilledbooleancheck if future has been fullfilled.
pendingbooleancheck if the promise is neither fulfilled nor rejected
promiseStatesymbol
reject(error?: unknown) => void

reject the future with given value.

the method has already bound to this, so you can write emitter.on('error', future.reject)

rejectedbooleancheck if future has been rejected.
resolve(value: T | PromiseLike<T>) => void

resolve the future with given value

tips: the method has already bound to this, so you can write emitter.on('event', future.resolve)

settledunknownget the promise settled result, for debug purpose only.
settledValue?T | unknown(Optional)