as await makes the function pause, then how does any web api resolves instantly as it first goes in callback queue and await until the call stack is empty. what i want to ask here is , how for eg setTimeout () gave us the result instant when called inside promises?
eg–> function wait(secondsToWait) {
return new Promise(resolve => {
setTimeout(
() => resolve(Resolved after ${secondsToWait} seconds
),
secondsToWait * 1000
);
});
}
async function fn() {
console.log(‘Beginning fn’);
const result = await wait(2);
console.log(result);
console.log('Ending fn');
}
fn();