Espruino/tests/test_promise.js
Gordon Williams (u36) c7943a7e9d multiple then/catch
2016-05-11 14:55:45 +01:00

30 lines
649 B
JavaScript

var p = new Promise(function(res,rej) {
setTimeout(res, 10, "Hello");
}).then(function(r) {
console.log("resolve ",r);
});
// Check that promises work even if the function is called immediately
var p = new Promise(function(res,rej) {
rej("Hello");
}).catch(function(r) {
console.log("reject", r);
});
var p = new Promise(function(res,rej) {
setTimeout(res, 10, "Hello");
}).then(function(r) {
console.log("resolve ",r);
});
var p = new Promise(function(res,rej) {
setTimeout(res, 10, "Hello");
}).then(function(r) {
console.log("resolve 1",r);
}).then(function(r) {
console.log("resolve 2",r);
});
trace(p);