Created
January 12, 2016 01:53
-
-
Save e2goon/548c4d947a4e08330cdb to your computer and use it in GitHub Desktop.
javascript promise pattern
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
function getItems() { | |
var promises = []; | |
promises.push(new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
resolve(); | |
}, Math.random() * 10000); | |
})); | |
return Promise.all(promises); | |
} | |
getItems | |
.then(function(items) { | |
// code | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment