Quantcast
Viewing all articles
Browse latest Browse all 11

Answer by Santosh Panda for What is the difference between synchronous and asynchronous programming (in node.js)

The difference between these two approaches is as follows:

Synchronous way:It waits for each operation to complete, after that only it executes the next operation.For your query:The console.log() command will not be executed until & unless the query has finished executing to get all the result from Database.

Asynchronous way:It never waits for each operation to complete, rather it executes all operations in the first GO only. The result of each operation will be handled once the result is available.For your query:The console.log() command will be executed soon after the Database.Query() method. While the Database query runs in the background and loads the result once it is finished retrieving the data.

Use cases

  1. If your operations are not doing very heavy lifting like querying huge data from DB then go ahead with Synchronous way otherwise Asynchronous way.

  2. In Asynchronous way you can show some Progress indicator to the user while in background you can continue with your heavy weight works. This is an ideal scenario for GUI apps.


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>