await is only valid in async function,

by Radhe Gupta
0 comment 128 views

In this blog post, I talk about the await keyword and how it is only valid in async functions.

I also discuss how you can use the await keyword to create asynchronous code that doesn’t have any callback functions. Points: – await is only valid in async function. It cannot be used with synchronous code. ‘this means that you can use the keyword without any other functions to control execution flow.’ – The await keyword does not have a return value, but it will wait until the promise has been fulfilled before continuing and returning from its call site. For example, `await Promise((resolve) => setTimeout(() => resolve(), 500)),` waits for half a second to finish resolving before completing its own asynchronous task of executing the `setTimeout`. This prevents errors such as having two tasks execute at once when one should logically happen after another. Await also saves CPU time because there are no callback

Related Posts

Leave a Comment