Skip to content

Instantly share code, notes, and snippets.

@fponticelli
Created March 11, 2015 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fponticelli/86b9d9d86cf63699494d to your computer and use it in GitHub Desktop.
Save fponticelli/86b9d9d86cf63699494d to your computer and use it in GitHub Desktop.
small js.Promise test
import js.Promise;
class Main {
static function main() {
var p1 = new Promise(function(resolve, reject) {
resolve("YES");
});
p1.then(function(v) trace(v), function(e) trace('NOOO!! $e'));
var p2 = new Promise(function(resolve, reject) {
reject("BAD");
});
p2.then(function(v) trace(v), function(e) trace('NOOO!! $e'));
Promise.all([p1,p2])
.then(function(_) {
trace(_);
})
.catchError(function(e) {
trace('Not again $e');
});
Promise.race([p1,p2])
.then(function(r) {
trace('Good, $r');
})
.catchError(function(e) {
trace('Not again $e');
});
Promise.all([p1,p2])
.then(function(_) return 1, function(_) return 2)
.then(function(n : Int) trace(n));
Promise.all([p1,p2])
.then(function(_) return Promise.respolve(11), function(_) return Promise.reject(2))
.then(function(n : Int) trace(n));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment