Created
December 24, 2015 03:23
-
-
Save benmccormick/434d57b05666030c1a8b to your computer and use it in GitHub Desktop.
Waiting on multiple async operations using Promises
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
//fetch makes an HTTP request and returns a promise that resolves | |
//when the file is loaded | |
let p1 = fetch('/data/file1.json'); | |
let p2 = fetch('/data/file2.json'); | |
let p3 = fetch('/data/file3.json'); | |
Promise.all([p1,p2,p3]).then(function(values) { | |
//values contains the responses from each of the promises | |
let [response1, response2, response3] = values; | |
doStuffWithResponses(response1, response2, response3); | |
}).catch(function() { | |
alert('failed to load one of the files') | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment