-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutdown.js
23 lines (22 loc) · 954 Bytes
/
shutdown.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { log } from "./log.js";
export const shutdown = ( cleaner, webSocketServer, httpsServer ) => () => {
let haveErrors = false;
console.log( "Exiting...\n\nClearing interval with cleaner of websocket connections..." );
clearInterval( cleaner );
console.log( "Interval cleared.\n\n" );
if ( httpsServer.listening ) {
console.log( "Closing WebSocket server..." );
webSocketServer.close( err => {
if ( err ) { log( err ); haveErrors = true; }
console.log( "WebSocket server closed.\n\nClosing http server..." );
httpsServer.close( err => {
if ( err ) { log( err ); haveErrors = true; }
console.log( "Http server closed." );
process.exit( ~~haveErrors );
} );
} );
} else {
console.log( "Http Server is not listening.\n\nWebSocket Server is not listening.\n\n" );
process.exit( 1 );
}
};