Add event listeners for cleanup

This commit is contained in:
Oliver-Akins 2020-09-29 22:57:48 -06:00
parent 729f6b7cd5
commit c2e28ce14b

View file

@ -1,4 +1,5 @@
import * as sio from "socket.io";
import { writeFileSync } from "fs";
import { Vote } from "./events/Vote";
import { JoinGame } from "./events/JoinGame";
import { HostGame } from "./events/HostGame";
@ -30,6 +31,11 @@ function clean_up() {
};
console.log(`Finished saving games to disk.`);
}
// Listen to the signals for the cleanup requirement
process.on(`uncaughtException`, clean_up);
process.on('SIGINT', clean_up);
const io = sio.listen(3000);
io.on(`connection`, (socket: sio.Socket) => {