new Future()
Represents the result of an action that may, or may not, have occurred yet.
- Source:
Methods
cause() → {todo}
A Throwable describing failure. This will be null if the operation succeeded.
- Source:
Returns:
the cause or null if the operation succeeded.
- Type
- todo
complete(result)
Set the result. Any handler will be called, if there is one, and the future will be marked as completed.
Parameters:
Name | Type | Description |
---|---|---|
result |
Object | the result |
- Source:
completer() → {function}
- Source:
Returns:
-
an handler completing this future
-
- Type
- function
compose(handler, composed) → {Future}
Compose this future with a provided
next
future.
When this future succeeds, the handler
will be called with the completed value, this handler
should complete the next future.
If the handler
throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the next
future and the handler
will not be called.
Parameters:
Name | Type | Description |
---|---|---|
handler |
function | the handler |
composed |
Future | the composed future |
- Source:
Returns:
the composed future, used for chaining
- Type
- Future
fail(failureMessage)
Set the failure. Any handler will be called, if there is one, and the future will be marked as completed.
Parameters:
Name | Type | Description |
---|---|---|
failureMessage |
string | the failure message |
- Source:
failed() → {boolean}
Did it fail?
- Source:
Returns:
true if it failed or false otherwise
- Type
- boolean
isComplete() → {boolean}
Has the future completed?
It's completed if it's either succeeded or failed.
- Source:
Returns:
true if completed, false if not
- Type
- boolean
map(value) → {Future}
Map the result of a future to a specific
value
.
When this future succeeds, this value
will complete the future returned by this method call.
When this future fails, the failure will be propagated to the returned future.
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | the value that eventually completes the mapped future |
- Source:
Returns:
the mapped future
- Type
- Future
result() → {Object}
The result of the operation. This will be null if the operation failed.
- Source:
Returns:
the result or null if the operation failed.
- Type
- Object
setHandler(handler) → {Future}
Set a handler for the result.
If the future has already been completed it will be called immediately. Otherwise it will be called when the future is completed.
Parameters:
Name | Type | Description |
---|---|---|
handler |
function | the Handler that will be called with the result |
- Source:
Returns:
a reference to this, so it can be used fluently
- Type
- Future
succeeded() → {boolean}
Did it succeed?
- Source:
Returns:
true if it succeded or false otherwise
- Type
- boolean