Skip to content

Instantly share code, notes, and snippets.

@foo9
Created May 2, 2015 03:38
Show Gist options
  • Save foo9/798f8f2af3ab06cee9e7 to your computer and use it in GitHub Desktop.
Save foo9/798f8f2af3ab06cee9e7 to your computer and use it in GitHub Desktop.
var count = 0;
function hoge() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
if (count < 2) {
resolve(count);
console.log((new Date()).getTime());
} else {
reject('fuga');
}
count++;
}, 1000);
});
}
Promise.all([
hoge(),
hoge(),
hoge()
]).then(function(results) {
console.log('success', results);
}).catch(function(error) {
console.log('fail', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment