Answer the question
In order to leave comments, you need to log in
What code can I use to block an output stream in Node.js?
I'm trying to understand with examples why all this asynchrony is needed in Node.js.
The manuals say that it is needed so that the output in Node is not blocked.
How exactly can I block it?
And then how can I solve this problem by making the code asynchronous?
Can I have the simplest example?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
I googled the answer))
https://habr.com/ru/post/150788/
A kind person was not too lazy to describe the essence of the problem with code examples.
Respect and respect))
For example, you read a file using readFileSync from some kind of slow file system, and at this time you still receive a thousand requests, and the node is busy, it is waiting for the file.
And I could use readFile, and while the file is being opened somewhere, the node would have time to process the requests.
Any request to external resources must be asynchronous.
Also, heavy calculations (huge cycles, for example) need to be divided into callback calls (setImmediate) so that some current operations are processed in between.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question