I
I
Ivan2022-01-13 10:07:36
JavaScript
Ivan, 2022-01-13 10:07:36

Will clients be served in Node if one of the clients is waiting?

Hello! Please tell me how node will behave in this case.
There is a telegram bot and at a certain moment, such a function is performed.

module.exports = async function (bot, message) {
await new Promise(resolve => setTimeout(resolve, 4000));
}


Its meaning is to take a timeout of 4 seconds.
If, during the timeout, another user accesses the bot, will node serve it?
Or will it wait until the timeout ends?

I ask the question because somewhere I read that node is single-threaded.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2022-01-13
@skapunker

Yes, other clients will be served.
The node is single-threaded, but setTimeout does not block the thread. Now, if you count something in this thread for all these four seconds, then the Node will not be able to answer another request, because it will be busy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question