From 2382fb8723fa7ee841aeb2ec816f284db75c5b38 Mon Sep 17 00:00:00 2001 From: canove Date: Thu, 24 Apr 2025 13:37:03 -0300 Subject: [PATCH 1/3] chore: avoid unhandled promise timeout errors --- src/Socket/socket.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index d097ed4..14beb65 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -187,7 +187,7 @@ export const makeSocket = (config: SocketConfig) => { let onRecv: (json) => void let onErr: (err) => void try { - return await promiseTimeout(timeoutMs, + const result = await promiseTimeout(timeoutMs, (resolve, reject) => { onRecv = resolve onErr = err => { @@ -199,6 +199,8 @@ export const makeSocket = (config: SocketConfig) => { ws.off('error', onErr) }, ) + + return result as any } finally { ws.off(`TAG:${msgId}`, onRecv!) ws.off('close', onErr!) // if the socket closes, you'll never receive the message @@ -213,11 +215,13 @@ export const makeSocket = (config: SocketConfig) => { } const msgId = node.attrs.id - const wait = waitForMessage(msgId, timeoutMs) - await sendNode(node) + const [result] = await Promise.all([ + waitForMessage(msgId, timeoutMs), + await sendNode(node) + ]) + - const result = await (wait as Promise) if('tag' in result) { assertNodeErrorFree(result) } From 2dbfb085d57fc4cde77aeb154731cd849aff61fd Mon Sep 17 00:00:00 2001 From: canove Date: Thu, 24 Apr 2025 13:38:00 -0300 Subject: [PATCH 2/3] chore: avoid unhandled promise timeout errors --- src/Socket/socket.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index 14beb65..5f78b65 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -221,7 +221,6 @@ export const makeSocket = (config: SocketConfig) => { await sendNode(node) ]) - if('tag' in result) { assertNodeErrorFree(result) } From 6d4ce2cb18e7908cc70a1a59b577b673d5eddff7 Mon Sep 17 00:00:00 2001 From: canove Date: Thu, 24 Apr 2025 13:38:43 -0300 Subject: [PATCH 3/3] chore: avoid unhandled promise timeout errors --- src/Socket/socket.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index 5f78b65..08f86b1 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -218,7 +218,7 @@ export const makeSocket = (config: SocketConfig) => { const [result] = await Promise.all([ waitForMessage(msgId, timeoutMs), - await sendNode(node) + sendNode(node) ]) if('tag' in result) {