From 3b9cc6dffbaddb072804f5461a668efc0b488e23 Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Wed, 15 Oct 2025 17:12:57 +0800 Subject: [PATCH] fix: attach finally cleanup to returned promise to avoid unhandled rejections --- src/core/RPCConnection.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/RPCConnection.ts b/src/core/RPCConnection.ts index 8e30261..199e10b 100644 --- a/src/core/RPCConnection.ts +++ b/src/core/RPCConnection.ts @@ -110,11 +110,6 @@ export class RPCConnection extends EventEmitter { return () => clearTimeout(t); })(); - promise.finally(() => { - this.callResponseEmitter.removeAllListeners(packet.id); - cancelTimeoutTimer(); - }) - const handleCallResponsePacket = (packet: RPCPacket) => { const result = parseCallResponsePacket(packet); if (result === null) { @@ -144,7 +139,10 @@ export class RPCConnection extends EventEmitter { /** send call request */ this.socket.send(packet); - return promise; + return promise.finally(() => { + this.callResponseEmitter.removeAllListeners(packet.id); + cancelTimeoutTimer(); + }); } public onCallRequest(getProvider: () => RPCProvider | undefined) { @@ -220,4 +218,8 @@ export class RPCConnection extends EventEmitter { return null; } } + + public async close() { + return this.socket.close(); + } } \ No newline at end of file