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

25 lines
518 B
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +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;
};