Created
March 11, 2015 14:46
-
-
Save fponticelli/86b9d9d86cf63699494d to your computer and use it in GitHub Desktop.
small js.Promise test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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