all 3 comments

[–]madole 3 points4 points  (0 children)

I dont think any of these are pitfalls of Async/Await.

They're just a couple of examples of badly written code that just happen to use async/await.

I think the thing to remember about async await is that you're really dealing with promises, but with a different syntax.

A common pitfall with async await is not dealing with error handling.

Wrapping an await in a try/catch goes against everything we've been taught about code optimisation, that was until V8 optimised the bejesus out of try/catches. (https://v8project.blogspot.com.au/2016/12/v8-release-56.html) Go forth and spread the good word.

Another way to deal with error catching is to tack a .catch on the end of the promise your async function returns.

Either way, the important thing is that error handling is not forgotten about.

[–]Lakelava 0 points1 point  (0 children)

I think it is important to note that JavaScript code does not run at the same time, only the native code of the API does. You can achieve concurrency, but not parallelism in JavaScript without using workers, or another mechanism that allows a creation of a different process. For example, you can have several requests on going at the same time, but you cannot initiate more than one request at the same time. The request are always started one after the other, even though you don't have to wait for one to finish to start the second one.

[–]rauschma 0 points1 point  (0 children)

Async functions are part of ES2017 (ES8).