Javascript : Non blocking / Async example

/**
 * Created by Aseem on 12/7/16.
 */

console.log("1: Start app")

var slowProcess = setTimeout(function(){
    console.log("2: app processing async - non blocking ");
},1000);

console.log("3: Exit app")

 

The out of this is non blocking, which mean the flow will not wait  or get blocked for slowProcess

Sample console output

➜ async git:(master) ✗ node nonBlocking.js
1: Start app
3: Exit app
2 : app processing async – non blocking

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s