• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How is the second Node.js program treated as async non blocking IO while first is treated as sync?

 
Ranch Hand
Posts: 1363
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the second Node.js program  treated as async non blocking IO while first is treated as sync blocking IO:

input.txt

This is sample text.

First Code:

main1.js



$ node main1.js

This is sample text.
Program ended.




Second:

main2.js




$ node main2.js

Program ended
This is sample text.


The second program is treated asyncronously as non blocking IO where as first is treated as sync blocking IO. What in the second code is making it treated async?
thanks
 
Monica Shiralkar
Ranch Hand
Posts: 1363
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the answer. Even though both are Node.js programs which are supposed to run asynchronously the first program is calling readFileSync method which is forcibly readonly the file synchronously. Otherwise by default it will run asynchronously.

 
Bras cause cancer. And tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!