Async Meaning

Here is a good explanation from a post on stackoverflow.

When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes.

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.

Leave a comment