mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-10 08:39:34 +00:00
refactor: improve shutdown cleanup
This commit is contained in:
committed by
Carlos Valente
parent
871a6b46c8
commit
4408bdb0d3
@@ -235,8 +235,25 @@ class SocketServer implements IAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.wss?.close();
|
||||
shutdown(): Promise<void> {
|
||||
const wss = this.wss;
|
||||
if (!wss) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// Notify clients first so they can reconnect gracefully
|
||||
for (const client of wss.clients) {
|
||||
if (client.readyState === WebSocket.OPEN || client.readyState === WebSocket.CONNECTING) {
|
||||
client.close(1001, 'Server shutting down');
|
||||
}
|
||||
}
|
||||
|
||||
wss.close(() => {
|
||||
this.wss = null;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user