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) }