Skip to content

Instantly share code, notes, and snippets.

@haiiro-shimeji
Last active April 21, 2017 02:34
Show Gist options
  • Save haiiro-shimeji/578cd44a81c04f6aec150fc7f2f71eae to your computer and use it in GitHub Desktop.
Save haiiro-shimeji/578cd44a81c04f6aec150fc7f2f71eae to your computer and use it in GitHub Desktop.
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