Don't leak promises
This commit is contained in:
parent
c94d732f24
commit
340c347841
1 changed files with 24 additions and 7 deletions
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue