Static variables

@:value(Future.NEVER)staticNEVER:Promise<Dynamic> = Future.NEVER

@:value(Future.sync(Success(Noise)))staticNOISE:Promise<Noise> = Future.sync(Success(Noise))

@:value(Future.sync(Success(null)))staticNULL:Promise<Dynamic> = Future.sync(Success(null))

Static methods

staticcache<T>(gen:() ‑> Promise<Pair<T, Future<Noise>>>):() ‑> Promise<T>

staticinParallel<T>(a:Array<Promise<T>>, ?concurrency:Int, ?lazy:Bool):Promise<Array<T>>


staticiterate<A, R>(promises:Iterable<Promise<A>>, yield:Next<A, Option<R>>, fallback:Promise<R>, ?lazy:Bool):Promise<R>

Given an Iterable (e.g. Array) of Promises, handle them one by one with the yield function until one of them yields Some value and the returned promise will resolve that value. If all of them yields None, the returned promise will resolve to the fallback promise. In a nutshell, it is the async version of the following code:

for(promise in promises) {
  switch yield(promise) {
    case Some(v): return v;
    case None:
return fallback;



An Iterable (e.g. Array) of Promises


A function used to handle the promises and should return an Option


A value to be used when all yields None







staticretry<T>(gen:() ‑> Promise<T>, next:Next<{error:Error, elapsed:Float, attempt:Int}, Noise>):Promise<T>

Retry a promise generator repeatedly



A function that returns a Promise, this function will be called multiple times during the retry process


A callback to be called when an attempt failed. An object will be received containing the info of the last attempt: attempt is the number of attempts tried, starting from 1 error is the error produced from the last attempt elasped is the amount of time (in ms) elapsed since the beginning of the retry call

If this function's returned promised resolves to an Error, this retry will abort with such error. Otherwise if it resolves to a Success(Noise), the retry will continue.

Some usage examples: - wait longer for later attempts and stop after a limit: `haxe function (info) return switch info.attempt {

  case 10: info.error;
  case v: Future.delay(v * 1000, Noise);

} `

  • bail out on error codes that are fatal: haxe function (info) return switch info.error.code { case Forbidden : info.error; // in this case new attempts probably make no sense default: Future.delay(1000, Noise); }

  • and also actually timeout: haxe // with using DateTools function (info) return if (info.elapsed > 2.minutes()) info.error else Future.delay(1000, Noise);




Creates a new PromiseTrigger



@:implinlineflatMap<R>(f:Outcome<T, Error> ‑> Future<R>):Future<R>


@:implinlinemap<R>(f:Outcome<T, Error> ‑> R):Future<R>

@:implmapError(f:Error ‑> Error):Promise<T>

@:value({ gather : true })@:implmerge<A, R>(other:Promise<A>, merger:Combiner<T, A, R>, gather:Bool = true):Promise<R>

@:value({ gather : true })@:implnext<R>(f:Next<T, R>, gather:Bool = true):Promise<R>





@:implinlinetryRecover(f:Next<Error, T>):Promise<T>