chore: isolate SSE client browsers (#76)

This commit is contained in:
Pavel Feldman
2025-03-28 13:24:45 -07:00
committed by GitHub
parent 889af3c853
commit 7bda082a4e
2 changed files with 99 additions and 65 deletions

View File

@@ -88,3 +88,29 @@ export function createServerWithTools(options: Options): Server {
return server;
}
export class ServerList {
private _servers: Server[] = [];
private _serverFactory: () => Server;
constructor(serverFactory: () => Server) {
this._serverFactory = serverFactory;
}
async create() {
const server = this._serverFactory();
this._servers.push(server);
return server;
}
async close(server: Server) {
const index = this._servers.indexOf(server);
if (index !== -1)
this._servers.splice(index, 1);
await server.close();
}
async closeAll() {
await Promise.all(this._servers.map(server => server.close()));
}
}