Answer the question
In order to leave comments, you need to log in
How to temporarily exclude a socket from participating in an event loop?
Suppose there is an object\array(*A) that stores sockets\connections\streams\... for later\reuse.
If you write a server application, then everything is fine.
If you write a CLI utility, then while the event loop has objects, the node itself will not complete the process.
But I want the node to ignore objects from *A, so as not to control when all asynchronous processes in the utility have completed and kill *A (or the whole process (generally unacceptable)).
How to temporarily exclude objects stored in *A from the event loop and include them in the event loop when necessary?
Answer the question
In order to leave comments, you need to log in
Node v0.9.1:
var socket = require('net').createConnection(23, function() {
setTimeout(10000, function() {
socket.unref(); // Исключили сокет из event loop
setTimeout(10000, function() {
// Нет нужды возвращать и закрывать сокет,
// так как он уже не в event loop
//socket.ref(); // Вернули сокет в event loop
//socket.end(); // Закрыли сокет
console.log('Last message!!!'); /* Когда сообщение будет выведено то нода завершит работу даже если socket все еще имеет соединение (!!!) так как он не участвует в event loop */
}
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question