B
B
beduin012016-03-06 11:17:49
Node.js
beduin01, 2016-03-06 11:17:49

What does data processing do in an asynchronous model?

Let's analyze it in more detail: we have an asynchronous reading from a file, when the read function is called, control is immediately transferred further, Node.js processes other requests. As soon as the file is read, the anonymous function passed to readFile as the second parameter is called. More precisely, the event associated with it is queued and when the queue reaches it, it is executed. Thus, we do not violate the sequence of actions: first the file is read, then it is processed. But at the same time, we do not take CPU time by waiting, but allow us to process other events in the queue.

The question is what will perform the read operation if the processor is already busy executing the following commands and it cannot switch between them in single-threaded mode. Will the device itself read the data without the control of the processor?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2016-03-06
@MAKAPOH

According to the documentation , to perform asynchronous operations related to the file system, the node launches several parallel threads.

I
Ilya Erokhin, 2016-03-07
@AirWorker

The most important thing to know is that the operating system interface is called, the Node itself does not read the file. Next is the operating system. As soon as a response is received on this call, the corresponding event will occur and the callback will be called.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question