It has been postulated (with sound reasoning) that top level await is a bad idea.

If so, are there any advantages to having await at all, when we already have yield.

Having async is useful because an async function is guaranteed to return a promise irrespective of what is actually returned by the code. But do have some similar reasoning behind await as well ?

Write your answer…

When @sandeep calls, I follow ;-)

Rich Harris's Gist-Blog post drew some attention :-)

What is async and await?

async/await is syntactical sugar on top of generator functions which yield Promises. Personally, I don't like the generator syntax; that's why I sparingly write any code like this function* fn() { yield maybe.something() }.

So I think async and await are excellent additions but as Rich Harris pointed out, the parser and code generators must do much better or only restrict its usage or use cases.

The more I think about it, the less I need async and await. Most of my problems are gone when we have widely accessible cancellable Promises. That would solve more of my code smell. Because who expects a Promise when one defines an async function() { which await maybe.something() }. I opened more questions then I answered, sorry ;-)

Clap1

The more I think about it, the less I need async and await. Most of my problems are gone when we have widely accessible cancellable Promises.

The primary reason I use control flow constructs (yield or async/await) is unified error handling through try-catch.

Reply to this…

Hashnode is building a friendly and inclusive dev community. Come jump on the bandwagon!

  • 💬 A beginner friendly place

  • 🧠 Stay in the loop and grow your knowledge

  • 🍕 >500K developers share programming wisdom here

  • ❤️ Support the growing dev community!

Register ( 500k+ developers strong 👊)