-
-
Save s22su/4046a81478047efdedc4 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 getProviderInfo = function (provider) | |
| { | |
| return new Promise(function (resolve, reject) { | |
| var time = ~~(Math.random() * 2000) + 2000; | |
| // Make request and get the data, simulate request api, no fail in our case | |
| window.setTimeout(function () { | |
| return resolve({ data: provider + " success in " + time }); | |
| }, time); | |
| }); | |
| }; | |
| var providers = [ | |
| getProviderInfo("facebook"), | |
| getProviderInfo("google"), | |
| getProviderInfo("linkedin"), | |
| getProviderInfo("twitter"), | |
| ]; | |
| var handleResult = function (result) | |
| { | |
| console.log("All the promises are resolved now we have data"); | |
| console.log("Result", result); | |
| }; | |
| Promise.all(providers).then(handleResult); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment