@@ -11,6 +11,7 @@ import Foundation
11
11
extension CbfClient {
12
12
// Track monitoring tasks per client for clean cancellation
13
13
private static var monitoringTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
14
+ private static var warningTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
14
15
private static var heartbeatTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
15
16
private static var lastInfoAt : [ ObjectIdentifier : Date ] = [ : ]
16
17
private static let monitoringTasksQueue = DispatchQueue ( label: " cbf.monitoring.tasks " )
@@ -132,6 +133,36 @@ extension CbfClient {
132
133
Self . monitoringTasksQueue. sync {
133
134
Self . heartbeatTasks [ id] = heartbeat
134
135
}
136
+
137
+ // Minimal warnings listener for visibility while syncing
138
+ let warnings = Task { [ self ] in
139
+ while true {
140
+ if Task . isCancelled { break }
141
+ do {
142
+ let warning = try await self . nextWarning ( )
143
+ #if DEBUG
144
+ print ( " [Kyoto][warning] \( String ( describing: warning) ) " )
145
+ #endif
146
+ if case . needConnections = warning {
147
+ await MainActor . run {
148
+ NotificationCenter . default. post (
149
+ name: NSNotification . Name ( " KyotoConnectionUpdate " ) ,
150
+ object: nil ,
151
+ userInfo: [ " connected " : false ]
152
+ )
153
+ }
154
+ }
155
+ } catch is CancellationError {
156
+ break
157
+ } catch {
158
+ // ignore
159
+ }
160
+ }
161
+ }
162
+
163
+ Self . monitoringTasksQueue. sync {
164
+ Self . warningTasks [ id] = warnings
165
+ }
135
166
}
136
167
137
168
func stopBackgroundMonitoring( ) {
@@ -140,15 +171,18 @@ extension CbfClient {
140
171
guard let task = Self . monitoringTasks. removeValue ( forKey: id) else { return }
141
172
task. cancel ( )
142
173
if let hb = Self . heartbeatTasks. removeValue ( forKey: id) { hb. cancel ( ) }
174
+ if let wt = Self . warningTasks. removeValue ( forKey: id) { wt. cancel ( ) }
143
175
Self . lastInfoAt. removeValue ( forKey: id)
144
176
}
145
177
}
146
178
147
179
static func cancelAllMonitoring( ) {
148
180
Self . monitoringTasksQueue. sync {
149
181
for (_, task) in Self . monitoringTasks { task. cancel ( ) }
182
+ for (_, wt) in Self . warningTasks { wt. cancel ( ) }
150
183
for (_, hb) in Self . heartbeatTasks { hb. cancel ( ) }
151
184
Self . monitoringTasks. removeAll ( )
185
+ Self . warningTasks. removeAll ( )
152
186
Self . heartbeatTasks. removeAll ( )
153
187
Self . lastInfoAt. removeAll ( )
154
188
}
0 commit comments