DEV Community

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

Collapse
 
fluffynuts profile image
Davyd McColl • Edited

Nice catch. I could hardly see all the text on my phone when I was typing. Was bound to have at least one glaring flaw (:

Now, I'm at a pc, I think I'd probably correct to:

$.get("/api/request1").then(function(result1) {
  return $.get("/api/request2?q=" + result1).then(function(result2) {
    return { result1, result2 };
  });
}).then(function(results) {
  console.log(results.result1 + " - " + results.result22);
});

(assuming I can use short notation for objects in this particular js-world)

And I think that illustrates even better why async/await is a win (: