await
↔ JS 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
async function
↔ JS Keyword to Declare function with Asynchronous Code to returnPromise
& allowawait
inside**Event Loop**
↔ (mechanism) to orchestrate Non-Blocking Concurrency Model by manageCallback Functions between Callback Queue& Call Stack, toawait
executeCallback Queue
↔ Data structure "todo" list of Callback Function toawait
execution