This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/killable/index.js
2019-08-11 20:48:02 +02:00

24 lines
518 B
JavaScript

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;
};