Last active
October 19, 2017 09:50
-
-
Save zlatkov/448a79cab54330c062a13a84ebb06cf7 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
async function loadData() { | |
// `rp` is a request-promise function. | |
var promise1 = rp('https://api.example.com/endpoint1'); | |
var promise2 = rp('https://api.example.com/endpoint2'); | |
// Currently, both requests are fired, concurrently and | |
// now we'll have to wait for them to finish | |
var response1 = await promise1; | |
var response2 = await promise2; | |
return response1 + ' ' + response2; | |
} | |
// Since, we're not in an `async function` anymore | |
// we have to use `then`. | |
loadData().then(() => console.log('Done')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! It's fixed.