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
Constructor | Modifiers | Description |
---|---|---|
(constructor)() | Constructs a new instance of the Future class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
_reject | (error: unknown) => void | ||
_resolve | (value: T | PromiseLike<T>) => void | ||
[Symbol.species] | static | PromiseConstructor | |
fulfilled | boolean | check if future has been fullfilled. | |
pending | boolean | check if the promise is neither fulfilled nor rejected | |
promiseState | symbol | ||
reject | (error?: unknown) => void | reject the future with given value. the method has already bound to | |
rejected | boolean | check if future has been rejected. | |
resolve | (value: T | PromiseLike<T>) => void | resolve the future with given value tips: the method has already bound to | |
settled | unknown | get the promise settled result, for debug purpose only. | |
settledValue? | T | unknown | (Optional) |