优化重启逻辑

This commit is contained in:
2026-09-22 19:38:53 +08:00
parent bcc1367291
commit 07d12ec470
2 changed files with 20 additions and 1 deletions
+7 -1
View File
@@ -38,7 +38,13 @@ function createBus() {
return set ? set.size : 0;
}
return { addClient, removeClient, emit, closeAll, clientCount };
// 进程退出前用:掐断所有会话的 SSE 流,让 server.close() 能等到连接清零
// (SSE 是长连接,不主动结束的话 close 回调永远不来)。
function closeAllSessions() {
for (const sessionId of Array.from(clients.keys())) closeAll(sessionId);
}
return { addClient, removeClient, emit, closeAll, closeAllSessions, clientCount };
}
module.exports = { createBus };