H
H
heIIfire2018-02-08 14:37:05
JavaScript
heIIfire, 2018-02-08 14:37:05

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

2 answer(s)
A
Alexey, 2018-02-08
@Azperin

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.

R
RidgeA, 2018-02-08
@RidgeA

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 ) {
}

then the process will not process other requests (callbacks)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question