Which code I can lock the output stream in Node.js?

I'm trying the examples to understand why all this async in Node.js.

In reference books write that it is needed to output in a Node are not blocked.

And how can I block for example?

And then how can I solve this problem by making the code asynchronous?

It can be the simplest example?

Thanks in advance.
March 23rd 20 at 19:47
3 answers
March 23rd 20 at 19:49
I googled the answer))


A kind person took the trouble to describe the problem with code examples.

Respect and uvazhuha))
March 23rd 20 at 19:51
For example read a file using readFileSync with some brake filesystem, but this time you have a thousand requests come in and a node is busy, it waits for the file.
And could use readFile, and while the file somewhere open, Noda requests could be processed.
Any request to external resources should be asynchronous.
As heavy calculations (huge loops for example) you need to break to call Korbakov (setImmediate) to processed some current operations in between.
March 23rd 20 at 19:53
Don't know about the locking of the output stream, but I know that if your synchronous code has operations like read from database, write the file somewhere on the hard drive, all sorts of network operations, it is recommended to use asynchronous code.
Those operations may slow down the implementation of all code that is causing the idle processor.
Asynchronous and need to, for example, when recording a file on the hard drive CPU is not idle, waiting for the end of recording the file and performed some kind of code.
Can watch 20-second clip https://learn.javascript.ru/screencast/nodejs - lynn.Tillman15 commented on March 23rd 20 at 19:56
, sorry, file not found.
If you are convinced that he there must surely be a report about it on github.

This is where they write) - corine_Wintheiser91 commented on March 23rd 20 at 19:59
Like should work now) - lynn.Tillman15 commented on March 23rd 20 at 20:02

Find more questions by tags Node.js