1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/killable/index.js

25 lines
518 B
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
module.exports = function makeKillable(server) {
var sockets = [];
server.on('connection', function (socket) {
//add socket to list
sockets.push(socket);
socket.once('close', function () {
//remove socket from list
sockets.splice(sockets.indexOf(socket), 1);
});
});
server.kill = function (cb) {
server.close(cb);
sockets.forEach(function (socket) {
socket.destroy();
});
// reset so the server can be restarted
sockets = [];
};
return server;
};