Here is a good explanation from a post on stackoverflow.
And here is an example I wrote on the javascript async function demo pageĀ
function FuncContainAsyncCall()
{
function ResolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function AsyncCall() {
console.log('calling');
var result = await ResolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
AsyncCall();
console.log("async won't block the flow!");
}
FuncContainAsyncCall();
> "calling"
> "async won't block the flow!"
> "resolved"
We can see from the console log that the async function won’t block the current execution flow so the execution can continue even the async function hasn’t finished yet.