Skip to main content

awaitJS Keyword to suspend execute JS code portion until Promise Settled & returns result

await must be used inside async function - when used in regular functions causes SyntaxError

!snippet async...await timer

(async function f(){
const result = await new Promise((resolve, reject) => {
setTimeout(() => resolve("1 second"), 1000)
});

alert(result)
})()

References

  1. async functionJS Keyword to Declare function with Asynchronous Code to return Promise & allow await inside

  2. **Event Loop** ↔ (mechanism) to orchestrate Non-Blocking Concurrency Model by manageCallback Functions between Callback Queue& Call Stack, to await execute

  3. Callback QueueData structure "todo" list of Callback Function to await execution