DEV Community

Discussion on: Explain Async/Await Like I'm Five

Collapse
 
patricktingen profile image
Patrick Tingen

So if you have this code (from Davyd above)

var result1 = await $.get("/api/request1");
var result2 = await $.get("/api/request2?q=" + result1);
console.log(result1 + " - " + result2);

Does the code wait until result1 is set and then continue with result2 or does it just make both calls and wait until both are ready?

Collapse
 
danieliverant profile image
Daniel Liverant

the code waits until result1 is set and just then continue to result2.
if you want to wait for them both to complete and then continue your code you need to use
await Promise.all([result1, result2])