What happens to Node.js events?

I have an Express application that uses an event emitter when resolving requests on a specific route. When the request is received, emit is called, which runs the code in the handler. This code takes about 5 seconds. What happens when an Express endpoint receives 10 or more requests per second at a time?

Will events be pushed onto the call stack and completed in the order in which they are pushed onto the call stack?

thank

status.emit('newCompletion')
+4
source share
1 answer

EventEmitter . , .emit() . , , .emit() .

, ?

. , , - eventEmitter. . .emit(), ( , .emit() ).

Express, . , emit, . 5 . , Express 10 ?

5 - , 5 . (, , TCP- ). , 5 , nodejs ( ), nodejs .

5 , 5 , 5 , . , node.js, . , . .emit() , , .

, .emit() , :

let em = new EventEmitter();
em.on("hello", function() {
    console.log("hello");
});


// schedule "immediate" task
setTimeout(function() {
    console.log("timer");
}, 0)

// schedule "immediate" micro-task
Promise.resolve().then(function() {
    console.log("promise");
});

em.emit("hello");
console.log("ready");
<script src="https://cdnjs.cloudflare.com/ajax/libs/EventEmitter/5.2.2/EventEmitter.js"></script>
Hide result
+4

Source: https://habr.com/ru/post/1684344/


All Articles