A type that represents an asynchronous value. This is often called Future

This implementation avoids stack problems some implementations have, but allows/requires the user to control resolution. A simple way to do this is to add Task.runner.resolve(); to your main loop.

Static variables

@:value({ })staticfinalread onlyrunner:BufferedRunner = { }

Static methods

staticalways<A, B>(t:Task<A>, value:B):Task<B>

When a given Task is resolved, discard its result and return value instead

staticany<A>(t:Task<A>):Bool

Returns:

true if this Task has already been resolved

staticap<A, B>(fn:Task<A ‑> B>, t:Task<A>):Task<B>

Applies a function to a value within the context of Tasks. Functions as a general sort of liftM

staticinlineasTask<X>(data:X):Task<X>

Lifts a known value into a completed Task

staticf_callbacks<A>(fn:(callback:A ‑> Void) ‑> Void):Task<A>

Lifts a side-effect that accepts a callback into a Task that runs the side effect and returns the input to the callback

Returns:

A Task that will contain the value passed to the callback

staticfilter<A>(t:Task<A>, predicate:A ‑> Bool):Task<Option<A>>

Discards the result of a Task if it does not match a given predicate

Returns:

a Task that returns a Some(value) that matches a predicate, or None

staticfilterFMap<A, B>(t:Task<A>, predicate:A ‑> Bool, fn:A ‑> Task<B>):Task<Option<B>>

staticfilterMap<A, B>(t:Task<A>, predicate:A ‑> Bool, fn:A ‑> B):Task<Option<B>>

staticflatMap<A, B>(t:Task<A>, fn:A ‑> Task<B>):Task<B>

staticflatten<A>(t:Task<Task<A>>):Task<A>

staticlogMessage<A>(t:Task<A>, genMessage:(data:A, pos:PosInfos) ‑> String, ?pos:Null<PosInfos>):Task<A>

When a task is complete, log a message to the console

staticmap<A, B>(t:Task<A>, fn:A ‑> B):Task<B>

staticmutate<A>(t:Task<A>, fn:A ‑> Void):Task<A>

Queues a side effect to be performed when a Task is complete

Returns:

The original Task

staticunit<A>(t:Task<A>):Task<Unit>

Waits for a task to complete and discards its result

staticzip<A, B>(ta:Task<A>, tb:Task<B>):Task<Pair<A, B>>

Returns:

A Task that returns a Pair of results from two Tasks

staticzipWith<A, B, C>(a:Task<A>, b:Task<B>, fn:(A, B) ‑> C):Task<C>

Apply a function to the results of 2 Tasks

staticzipWith3<A, B, C, Z>(a:Task<A>, b:Task<B>, c:Task<C>, fn:(A, B, C) ‑> Z):Task<Z>

Apply a function to the results of 3 Tasks

Constructor

@:value({ data : null })new(?data:A)

Variables

@:value(null)read onlydata:Null<A> = null

@:value(false)read onlyisComplete:Bool = false

@:value([])read onlyobservers:Array<A ‑> Void> = []

Methods

resolve(data:A):A

Completes a Task with a given result