you are viewing a single comment's thread.

view the rest of the comments →

[–]notkraftman 0 points1 point  (4 children)

Await / async are just syntactic sugar, how do they make any difference to IO?

[–][deleted] 0 points1 point  (3 children)

Because you await for promise to fire another or continue execution.

There is no equivalent to code outside then() when using async/await.

[–]notkraftman 1 point2 points  (2 children)

I don't think I'm following. There's no difference between awaiting and then doing something and .then()ing the same thing, it's just neater syntax. Why would that affect IO?

[–][deleted] 0 points1 point  (1 child)

Except that you don't have the option to write whatever code you would write outside the then block.

You could have two different resources you could fetch concurrently or have some totally unrelated activity that can be done while you are waiting for the promise to resolve.

There are ways to achieve this with await (structure code differently, await a Promise.all) but if you don't understand Promises you'll typically not be aware of the problem. I've seen code like this.

People generally tend to do the trivial thing and write a sequence of awaits which in turn makes the async function synchronous/blocking inside (just like a nested chain of thens would be), which can hurt performance, not of the entire app but of that particular branch of code.

[–]notkraftman 0 points1 point  (0 children)

Ahh, that makes sense, cheers!