abstract Future<T>(FutureObject<T>)
package tink.core
from FutureObject<T>, FutureTrigger<T>, to FutureObject<T>,
Representation of the result of a potentially asynchronous operation. It can be handled by registering
a callback using the handle
method. These callbacks will be invoked as soon as the result becomes available.
Note that Future
by itself doesn't differentiate successful and failed operations, because it doesn't always
make sense. See Outcome
and Promise
types that are designed to represent potential failures.
Static variables
Static methods
staticasync<A>(init:A ‑> Void ‑> Void, lazy:Bool = false):Future<A>
staticinlineeager(this:FutureObject<T>):Future<T>
Makes this future eager.
* Futures are lazy by default, i.e. it does not try to fetch the result until someone handle
it
staticfirst(this:FutureObject<T>, that:Future<T>):Future<T>
Creates a future that contains the first result from this
or that
staticflatMap<A>(this:FutureObject<T>, next:T ‑> Future<A>, ?gather:Gather):Future<A>
Creates a new future by applying a transform function to the result.
* Different from map
, the transform function of flatMap
returns a Future
staticinlinehandle(this:FutureObject<T>, callback:Callback<T>):CallbackLink
Registers a callback to handle the future result.
If the result is already available, the callback will be invoked immediately.
@return A CallbackLink
instance that can be used to cancel the callback, no effect if the callback is already invoked
staticinSequence<T>(futures:Array<Future<T>>):Future<Array<T>>
staticirreversible<A>(init:A ‑> Void ‑> Void):Future<A>
Creates an irreversible future:
init
gets called, when the first handler is registered or eager()
is called.
The future is never suspended again. When possible, use new Future()
instead.
staticmap<A>(this:FutureObject<T>, f:T ‑> A, ?gather:Gather):Future<A>
Creates a new future by applying a transform function to the result.
* Different from flatMap
, the transform function of map
returns a sync value
staticmerge<A, R>(this:FutureObject<T>, that:Future<A>, combine:(T, A) ‑> R):Future<R>
Merges two futures into one by applying combine
on the two future values
staticinlinesync<A>(v:A):Future<A>
Creates a sync future.
* Example: var i = Future.sync(1); // Future<Int>