Don't leak promises

This commit is contained in:
Andras Schmelczer 2025-11-23 16:45:27 +00:00
commit 340c347841

View file

@ -195,9 +195,17 @@ export class WebSocketManager {
): Promise<void> { ): Promise<void> {
if (message.type === "vaultUpdate") { if (message.type === "vaultUpdate") {
this.outstandingPromises.push( this.outstandingPromises.push(
...this.remoteVaultUpdateListeners.map(async (listener) => ...this.remoteVaultUpdateListeners.map(async (listener) => {
listener(message) const promise = listener(message);
) return promise.finally(() => {
if (this.outstandingPromises.includes(promise)) {
this.outstandingPromises.splice(
this.outstandingPromises.indexOf(promise),
1
);
}
});
})
); );
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if (message.type === "cursorPositions") { } else if (message.type === "cursorPositions") {
@ -205,13 +213,22 @@ export class WebSocketManager {
`Received cursor positions for ${JSON.stringify(message.clients)}` `Received cursor positions for ${JSON.stringify(message.clients)}`
); );
this.outstandingPromises.push( this.outstandingPromises.push(
...this.remoteCursorsUpdateListeners.map(async (listener) => ...this.remoteCursorsUpdateListeners.map(async (listener) => {
listener( const promise = listener(
message.clients.filter( message.clients.filter(
(client) => client.deviceId !== this.deviceId (client) => client.deviceId !== this.deviceId
) )
) );
)
return promise.finally(() => {
if (this.outstandingPromises.includes(promise)) {
this.outstandingPromises.splice(
this.outstandingPromises.indexOf(promise),
1
);
}
});
})
); );
} else { } else {
this.logger.warn( this.logger.warn(