DEV Community

Discussion on: Why async code is so damn confusing (and a how to make it easy)

Collapse
 
joelnet profile image
JavaScript Joel

That's true, you could just await everything. You can even do this:

const x = await 5

In the case of this problem:

// await `action()`
await thing().action()

// await `thing()`
(await thing()).action()

You could do this and not worry.

// await all the things
await (await thing()).action()

But I would probably go insane.

Collapse
 
vhoyer profile image
Vinícius Hoyer

while it is true you could await every thing, there is a difference. the await operator will always wait till the next tick to start checking for the resolving of a promise, even if your promise is a literal. But thats just what I read somewhere that I don't remember where, sorry for the lack of reference, yet I'm pretty confident in the information.

Thread Thread
 
joelnet profile image
JavaScript Joel

I believe you were correct about this. Adding extraneous awaits could have a performance impace.