Skip to content

Commit

Permalink
Unsubscribe and GC listeners in a loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-dp committed Nov 29, 2023
1 parent 2a5e7a5 commit 89029ad
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions clients/typescript/src/satellite/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 89029ad

Please sign in to comment.