Last active
April 21, 2017 02:34
-
-
Save haiiro-shimeji/578cd44a81c04f6aec150fc7f2f71eae to your computer and use it in GitHub Desktop.
This file contains 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
console.log('hoge'); | |
Promise.resolve() | |
.then(function() { | |
return new Promise(function(resolve) { | |
setTimeout(function() { | |
resolve('fuga'); | |
}, 1000); | |
}); | |
}) | |
.then(function(message) { | |
console.log(message); | |
}) | |
.then(function(message) { | |
return Promise.all([ | |
new Promise(function(resolve) { | |
setTimeout(function() { | |
resolve('foo'); | |
}, 2000); | |
}), | |
new Promise(function(resolve) { | |
setTimeout(function() { | |
resolve('bar'); | |
}, 3000); | |
}), | |
]); | |
}) | |
.then(function(message) { | |
console.log(message); | |
}) | |
.then(function(message) { | |
return Promise.race([ | |
new Promise(function(_, reject) { | |
setTimeout(function() { | |
reject('bar'); | |
}, 2000); | |
}), | |
new Promise(function(resolve) { | |
setTimeout(function() { | |
resolve('baz'); | |
}, 3000); | |
}), | |
]); | |
}) | |
.then(function(message) { | |
console.log('result: '+message); | |
}) | |
.catch(function(cause) { | |
console.log('error: '+cause); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment