Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup disconnect and unsubscribe calls #41

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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