From fe18a3332131b259c5b0b3f2653a37e73d0ebcaa Mon Sep 17 00:00:00 2001 From: Aravind Raveendran Date: Wed, 18 Oct 2023 14:26:01 +1100 Subject: [PATCH] Cleanup disconnect and unsubscribe calls --- .../Manager/SubscriptionManager.swift | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Sources/DolbyIORTSCore/Manager/SubscriptionManager.swift b/Sources/DolbyIORTSCore/Manager/SubscriptionManager.swift index 64e8004..0117509 100644 --- a/Sources/DolbyIORTSCore/Manager/SubscriptionManager.swift +++ b/Sources/DolbyIORTSCore/Manager/SubscriptionManager.swift @@ -64,10 +64,6 @@ final class SubscriptionManager: SubscriptionManagerProtocol { weak var delegate: SubscriptionManagerDelegate? func connect(streamName: String, accountID: String, configuration: SubscriptionConfiguration) async -> Bool { - if subscriber != nil { - _ = await stopSubscribe() - } - guard let subscriber = makeSubscriber(with: configuration) else { Self.logger.error("💼 Failed to initialise subscriber") return false @@ -145,19 +141,22 @@ final class SubscriptionManager: SubscriptionManagerProtocol { return false } - guard subscriber.unsubscribe() else { + defer { + self.subscriber.setListener(nil) + self.subscriber = nil + } + + let unsubscribeResult = subscriber.unsubscribe() + if !unsubscribeResult { Self.logger.error("💼 Failed to unsubscribe") - return false } - - guard subscriber.disconnect() else { + + let disconnectResult = subscriber.disconnect() + if !disconnectResult { Self.logger.error("💼 Failed to disconnect") - return false } - - self.subscriber = nil - - return true + + return disconnectResult && unsubscribeResult } return await task.value }