katoikia-app/web-ui/web-react/node_modules/killable/index.js

25 lines
518 B
JavaScript
Raw Normal View History

2022-07-06 04:15:11 +00: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;
};