feat: Cleaning up some unused code.
This commit is contained in:
@@ -12,7 +12,11 @@ public extension MQTTConnectionManager {
|
||||
let manager = ConnectionManager(client: client, logger: logger)
|
||||
return .init { _ in
|
||||
try await manager.connect(cleanSession: cleanSession)
|
||||
|
||||
return manager.stream
|
||||
.removeDuplicates()
|
||||
.eraseToStream()
|
||||
|
||||
} shutdown: {
|
||||
manager.shutdown()
|
||||
}
|
||||
@@ -26,6 +30,7 @@ private actor ConnectionManager {
|
||||
private let continuation: AsyncStream<MQTTConnectionManager.Event>.Continuation
|
||||
private nonisolated let logger: Logger?
|
||||
private let name: String
|
||||
private var started: Bool = false
|
||||
let stream: AsyncStream<MQTTConnectionManager.Event>
|
||||
|
||||
init(
|
||||
@@ -42,6 +47,7 @@ private actor ConnectionManager {
|
||||
|
||||
deinit {
|
||||
client.removeCloseListener(named: name)
|
||||
client.removeShutdownListener(named: name)
|
||||
}
|
||||
|
||||
func connect(cleanSession: Bool) async throws {
|
||||
@@ -51,13 +57,16 @@ private actor ConnectionManager {
|
||||
continuation.yield(.connected)
|
||||
|
||||
client.addCloseListener(named: name) { _ in
|
||||
Task {
|
||||
self.continuation.yield(.disconnected)
|
||||
self.logger?.debug("Connection closed.")
|
||||
self.logger?.debug("Reconnecting...")
|
||||
try await self.connect(cleanSession: cleanSession)
|
||||
}
|
||||
self.continuation.yield(.disconnected)
|
||||
self.logger?.debug("Connection closed.")
|
||||
self.logger?.debug("Reconnecting...")
|
||||
Task { try await self.connect(cleanSession: cleanSession) }
|
||||
}
|
||||
|
||||
client.addShutdownListener(named: name) { _ in
|
||||
self.shutdown()
|
||||
}
|
||||
|
||||
} catch {
|
||||
client.logger.trace("Failed to connect: \(error)")
|
||||
continuation.yield(.disconnected)
|
||||
@@ -66,6 +75,7 @@ private actor ConnectionManager {
|
||||
}
|
||||
|
||||
nonisolated func shutdown() {
|
||||
client.logger.trace("Shutting down connection.")
|
||||
continuation.yield(.shuttingDown)
|
||||
continuation.finish()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user