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

@:value(((new NeverFuture() : FutureObject<Never>)))staticfinalread onlyNEVER:Future<Never> = ((new NeverFuture() : FutureObject<Never>))

@:value(Future.sync(Noise))staticfinalread onlyNOISE:Future<Noise> = Future.sync(Noise)

@:value(NOISE)staticfinalread onlyNULL:Future<Noise> = NOISE

Deprecated: "use Future.NOISE instead"

staticread onlystatus:FutureStatus<T>

Static methods

staticinlineasPromise<T>(s:Surprise<T, Error>):Promise<T>

Casts a Surprise into a Promise

@:value({ lazy : false })@:noUsingstaticasync<A>(init:A ‑> Void ‑> Void, lazy:Bool = false):Future<A>

Deprecated: "use Future.irreversible() - or better yet: new Future()"

@:noUsingstaticdelay<T>(ms:Int, value:Lazy<T>):Future<T>

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

staticflatten<A>(f:Future<Future<A>>):Future<A>

Flattens Future<Future<A>> into Future<A>

staticinlinegather(this:FutureObject<T>):Future<T>

Deprecated: "Gathering no longer has any effect"

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

@:noUsingstaticinParallel<T>(futures:Array<Future<T>>, ?concurrency:Int):Future<Array<T>>

Merges multiple futures into a Future<Array<A>> The futures are processed simultaneously. Set concurrency to limit how many are processed at a time.

@:noUsingstaticinSequence<T>(futures:Array<Future<T>>):Future<Array<T>>

Merges multiple futures into a Future<Array<A>> The futures are processed one at a time.

@:noUsingstaticirreversible<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.

@:noUsingstaticinlineisFuture(maybeFuture:Dynamic):Bool

@:noUsingstaticinlinelazy<A>(l:Lazy<A>):Future<A>

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

staticinlinenext<R>(this:FutureObject<T>, n:Next<T, R>):Promise<R>

Like map and flatMap but with a polymorphic transformer and return a Promise * @see Next

@:tostaticnoise(this:FutureObject<T>):Future<Noise>

@:noUsingstaticinlinesync<A>(v:A):Future<A>

Creates a sync future. * Example: var i = Future.sync(1); // Future<Int>

@:noUsingstaticinlinetrigger<A>():FutureTrigger<A>

Creates a new FutureTrigger