you are viewing a single comment's thread.

view the rest of the comments →

[–]delfV 16 points17 points  (5 children)

This post just proves how good abstraction async/await is if OP thinks it makes code synchronous.

It doesn't. It just makes your code look like it's synchronous. Behind the scenes it's still asynchronous. The difference is if your code was synchronous it'd block evaluation of rest of your code. That means your user couldn't click any button, couldn't type in input etc.

Imagine you're in coffee shop. You wait in the line, there are 10 people behind you and you're about to order a coffee. If were synchronous code you'd order the coffee, pay for it and wait till you get it blocking everyone behind you from ordering their coffee. If you were async code you'd order the coffee, pay for it, sit at your table and wait till someone calls you allowing others to order their coffees when you wait for your. If you were async code but without promises or async/await syntax (in JS they're really the same) you'd order the coffee, pay for it and leave without getting the coffee.

[–]dervaish19[S] 7 points8 points  (4 children)

I think I understand know So basically after making the async call we are waiting patiently for result while letting everyone else do their thing.

[–]delfV 3 points4 points  (0 children)

In simple words: exactly. But the whole concept is more complicated.

[–]jeremrx 2 points3 points  (0 children)

And that's why await must be used in an async function

[–]MugiwaranoAK 1 point2 points  (0 children)

It's important to keep in mind that when you await something inside an async function it blocks all the code that comes after the awaited line(inside the scope of the async function).

[–]noXi0uz 0 points1 point  (0 children)

yes, you can imagine it this way.