Skip to content

Commit

Permalink
Merge pull request #41 from DolbyIO/bugfix/unsubscribe-and-disconnect…
Browse files Browse the repository at this point in the history
…-cleanup

Cleanup disconnect and unsubscribe calls
  • Loading branch information
aravind-raveendran authored Oct 18, 2023
2 parents 5ac5969 + fe18a33 commit a4b7879
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions Sources/DolbyIORTSCore/Manager/SubscriptionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a4b7879

Please sign in to comment.