Use of await in async functions

Shan Shaji
1 min readJan 31, 2023

--

await is used to pause the execution of an asynchronous function and wait for a Promise to be resolved. It can only be used within an async function. The await keyword allows you to wait for the result of an asynchronous operation before moving on to the next line of code, making the code appear more like synchronous code.

Do we need to wait for all asynchronous codes🤔?

Not necessarily. In many cases, asynchronous code can run independently and does not require the main thread to wait for it to complete. This allows for the program to continue executing other tasks while the asynchronous operation is being performed in the background. However, there are cases where you may want to wait for the completion of an asynchronous operation, and in those cases, you can use the await keyword to pause the execution of the code until the Promise is resolved.

--

--

Shan Shaji
Shan Shaji

Written by Shan Shaji

Skilled in Flutter, React, MongoDB, Express, and Typescript. Experienced with Flutter architectures, state management, Firebase, and cloud functions.

No responses yet