Created
May 2, 2015 03:38
-
-
Save foo9/798f8f2af3ab06cee9e7 to your computer and use it in GitHub Desktop.
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
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