Future

Future

A Promise-like object that allows for easy external fulfillment. Future objects can also be cancelled to indicate to the fulfiller that the Future is no longer being used. Modeled after Python's asyncio.Future

Constructor

new Future()

Source:

Extends

Classes

Future

Methods

addImmediateCallback(callback)

Source:
Add a callback that is executed immediately on fulfillment of the Future. For some use cases it is not acceptable to let the event loop run other tasks before a finalizer of some sort is run. E.g. Lock and Queue.
Parameters:
Name Type Description
callback function A callback that is invoked with this Future.

cancel() → {boolean}

Source:
Cancel the future and run callbacks.
Returns:
true if Future was pending, otherwise false
Type
boolean

cancelled() → {boolean}

Source:
Indicates if the Future was cancelled.
Returns:
Type
boolean

done() → {boolean}

Source:
Indicates if the Future is fulfilled.
Returns:
Type
boolean

error() → {Error}

Source:
Return the Error of a fulfilled but rejected Future. If the Future is not fulfilled it will throw an Error.
Returns:
Type
Error

result() → {*}

Source:
Return the result of a fulfilled Future. If the Future is not fulfilled it will throw an Error.
Returns:
Type
*

setError(e)

Source:
Set the Error of a Future and reject it. The Future will be put into the fulfilled state and any functions awaiting the result will be resumed on the next event loop tick.
Parameters:
Name Type Description
e Error A valid Error that will be thrown to awaiters.

setResult(result)

Source:
Set the result of a Future and resolve it. The Future will be put into the fulfilled state and any functions awaiting the result will be resumed on the next event loop tick.
Parameters:
Name Type Description
result * Any value that should be passed to awaiters.