Answer the question
In order to leave comments, you need to log in
Are the actions in the event loop executed sequentially or in parallel?
Let's say we have 2 users - Sasha and Petya.
Sasha visits the site and performs an action that requires 10 seconds of time. That is, a callback gets into the event loop, which requires 10 seconds to complete.
At this time, Petya also performs the same action. But in the event loop, Sasha's action is performed in this one.
Please explain what I misunderstood. Thanks in advance
Answer the question
In order to leave comments, you need to log in
Parallel to what? If Sasha performs an action that blocks the application for 10 seconds, then not only Petya, but everyone else will be waiting there. You can simulate any other situation with setTimeout. The event loop is a loop, because there are no flows as such, you can of course cram workers into the node, but that's another story.
Here you need to clarify what kind of operation it is.
If this is a network call, reading a file (except for fs.readFileSync and other *Sync operations), where the answer comes in 10 seconds, then everything is OK, the callback will just work when the answer comes.
If it's something like
let start = Date.now()
for (Date.now() < start + 10 * 1000 ) {
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question