fix(typedsocket): reject pending requests on disconnect to avoid hanging promises
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedsocket',
|
||||
version: '4.1.0',
|
||||
version: '4.1.1',
|
||||
description: 'A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.'
|
||||
}
|
||||
|
||||
@@ -325,6 +325,12 @@ export class TypedSocket {
|
||||
|
||||
this.updateStatus('disconnected');
|
||||
|
||||
// Reject all pending requests — the connection is gone and they'll never receive a response
|
||||
for (const [id, pending] of this.pendingRequests) {
|
||||
pending.reject(new Error('TypedSocket disconnected'));
|
||||
}
|
||||
this.pendingRequests.clear();
|
||||
|
||||
if (this.clientOptions?.autoReconnect && this.retryCount < this.clientOptions.maxRetries) {
|
||||
this.scheduleReconnect();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user