Skip to content

Instantly share code, notes, and snippets.

@zlatkov
Last active October 19, 2017 09:50
Show Gist options
  • Save zlatkov/448a79cab54330c062a13a84ebb06cf7 to your computer and use it in GitHub Desktop.
Save zlatkov/448a79cab54330c062a13a84ebb06cf7 to your computer and use it in GitHub Desktop.
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'));
@zlatkov
Copy link
Author

zlatkov commented Oct 19, 2017

Thanks! It's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment