Skip to content

Instantly share code, notes, and snippets.

@alebianco
Created June 30, 2015 07:58
Show Gist options
  • Save alebianco/15a52b27460369e75115 to your computer and use it in GitHub Desktop.
Save alebianco/15a52b27460369e75115 to your computer and use it in GitHub Desktop.
Promhx error catching test
package ;
import haxe.Timer;
import promhx.Deferred;
import promhx.Promise;
class Main {
public static var instance:Main;
public function new() {
setOne();
}
public function setOne() {
var d1 = new Deferred<Int>();
var d2 = new Deferred<Int>();
var d3 = new Deferred<Int>();
var p1 = d1.promise();
var p2 = d2.promise();
var p3 = d3.promise();
Promise.whenAll([p1, p2, p3]).then(function(a:Array<Int>) {
trace("set one resolved with: " + a);
setTwo();
}).catchError(function(e:Dynamic) {
trace("set one failed with: " + e);
});
Timer.delay(d1.resolve.bind(1), 20);
Timer.delay(d2.resolve.bind(2), 5);
Timer.delay(d3.resolve.bind(3), 10);
}
public function setTwo() {
var d4 = new Deferred<Int>();
var d5 = new Deferred<Int>();
var d6 = new Deferred<Int>();
var p4 = d4.promise();
var p5 = d5.promise();
var p6 = d6.promise();
throw "there was a mistake, i'll break set one now ...";
Promise.whenAll([p4, p5, p6]).then(function(a:Array<Int>) {
trace("set two resolved with: " + a);
}).catchError(function(e:Dynamic) {
trace("set two failed with: " + e);
});
Timer.delay(d4.resolve.bind(4), 20);
Timer.delay(d5.throwError.bind("i'll break set two"), 5);
Timer.delay(d6.resolve.bind(5), 10);
}
static function main() {
instance = new Main();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment