fix: use setImmediate to reduce flakiness when processing events (#12264)

This commit is contained in:
Alex Rudenko 2024-04-12 11:45:32 +02:00 committed by GitHub
parent ff4f70f4ae
commit 73403b323e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,14 +41,18 @@ export class NodeWebSocketTransport implements ConnectionTransport {
constructor(ws: NodeWebSocket) { constructor(ws: NodeWebSocket) {
this.#ws = ws; this.#ws = ws;
this.#ws.addEventListener('message', event => { this.#ws.addEventListener('message', event => {
if (this.onmessage) { setImmediate(() => {
this.onmessage.call(null, event.data); if (this.onmessage) {
} this.onmessage.call(null, event.data);
}
});
}); });
this.#ws.addEventListener('close', () => { this.#ws.addEventListener('close', () => {
if (this.onclose) { setImmediate(() => {
this.onclose.call(null); if (this.onclose) {
} this.onclose.call(null);
}
});
}); });
// Silently ignore all errors - we don't know what to do with them. // Silently ignore all errors - we don't know what to do with them.
this.#ws.addEventListener('error', () => {}); this.#ws.addEventListener('error', () => {});