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) {
this.#ws = ws;
this.#ws.addEventListener('message', event => {
if (this.onmessage) {
this.onmessage.call(null, event.data);
}
setImmediate(() => {
if (this.onmessage) {
this.onmessage.call(null, event.data);
}
});
});
this.#ws.addEventListener('close', () => {
if (this.onclose) {
this.onclose.call(null);
}
setImmediate(() => {
if (this.onclose) {
this.onclose.call(null);
}
});
});
// Silently ignore all errors - we don't know what to do with them.
this.#ws.addEventListener('error', () => {});