fix: attach finally cleanup to returned promise to avoid unhandled rejections
This commit is contained in:
@@ -110,11 +110,6 @@ export class RPCConnection extends EventEmitter<RPCConnectionEvents> {
|
||||
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<RPCConnectionEvents> {
|
||||
/** 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<RPCConnectionEvents> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async close() {
|
||||
return this.socket.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user