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,15 +41,19 @@ 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 => {
setImmediate(() => {
if (this.onmessage) { if (this.onmessage) {
this.onmessage.call(null, event.data); this.onmessage.call(null, event.data);
} }
}); });
});
this.#ws.addEventListener('close', () => { this.#ws.addEventListener('close', () => {
setImmediate(() => {
if (this.onclose) { if (this.onclose) {
this.onclose.call(null); 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', () => {});
} }