Event Loop and Source Panels
Async Await Steps
Use await to pause and resume a small calculation.
Async Await Steps
async_await_steps.js
const fetched = 8;
let prepared = 0;
let score = 0;
async function calculate(value) {
prepared = value + 1;
const remote = await Promise.resolve(prepared + 9);
score = remote;
console.log("fetched=" + fetched);
console.log("prepared=" + prepared);
console.log("score=" + score);
}
calculate(fetched);
async-await
`await` pauses the async function until the Promise value is ready, then execution resumes inside the same source.