From 89029adf4d60b9f11f39496dff6df80accc54356 Mon Sep 17 00:00:00 2001 From: Kevin De Porre Date: Wed, 29 Nov 2023 17:37:41 +0100 Subject: [PATCH] Unsubscribe and GC listeners in a loop. --- clients/typescript/src/satellite/process.ts | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/clients/typescript/src/satellite/process.ts b/clients/typescript/src/satellite/process.ts index e886c9bb99..fd831262ce 100644 --- a/clients/typescript/src/satellite/process.ts +++ b/clients/typescript/src/satellite/process.ts @@ -352,20 +352,20 @@ export class SatelliteProcess implements Satellite { this._pollingInterval = undefined } - if (this._unsubscribeFromAuthState !== undefined) { - this._unsubscribeFromAuthState() - this._unsubscribeFromAuthState = undefined - } - - if (this._unsubscribeFromConnectivityChanges !== undefined) { - this._unsubscribeFromConnectivityChanges() - this._unsubscribeFromConnectivityChanges = undefined - } - - if (this._unsubscribeFromPotentialDataChanges !== undefined) { - this._unsubscribeFromPotentialDataChanges() - this._unsubscribeFromPotentialDataChanges = undefined - } + // Unsubscribe all listeners and remove them + const unsubscribers = [ + '_unsubscribeFromAuthState', + '_unsubscribeFromConnectivityChanges', + '_unsubscribeFromPotentialDataChanges', + ] as const + + unsubscribers.forEach((unsubscriber) => { + const unsub = this[unsubscriber] + if (unsub !== undefined) { + unsub!() + this[unsubscriber] = undefined + } + }) this._disconnect()