Skip to content

Commit 466fa26

Browse files
committed
chore: temp logging nextlog
1 parent 19be079 commit 466fa26

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

BDKSwiftExampleWallet/Extensions/BDK+Extensions/CbfClient+Extensions.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extension CbfClient {
1212
// Track monitoring tasks per client for clean cancellation
1313
private static var monitoringTasks: [ObjectIdentifier: Task<Void, Never>] = [:]
1414
private static var warningTasks: [ObjectIdentifier: Task<Void, Never>] = [:]
15+
private static var logTasks: [ObjectIdentifier: Task<Void, Never>] = [:]
1516
private static var heartbeatTasks: [ObjectIdentifier: Task<Void, Never>] = [:]
1617
private static var lastInfoAt: [ObjectIdentifier: Date] = [:]
1718
private static let monitoringTasksQueue = DispatchQueue(label: "cbf.monitoring.tasks")
@@ -179,6 +180,30 @@ extension CbfClient {
179180
Self.monitoringTasksQueue.sync {
180181
Self.warningTasks[id] = warnings
181182
}
183+
184+
// Log listener for detailed debugging
185+
let logs = Task { [self] in
186+
while true {
187+
if Task.isCancelled { break }
188+
do {
189+
#if DEBUG
190+
print("[Kyoto] calling nextLog()")
191+
#endif
192+
let log = try await self.nextLog()
193+
#if DEBUG
194+
print("[Kyoto] nextLog() returned: \(log)")
195+
#endif
196+
} catch is CancellationError {
197+
break
198+
} catch {
199+
// ignore
200+
}
201+
}
202+
}
203+
204+
Self.monitoringTasksQueue.sync {
205+
Self.logTasks[id] = logs
206+
}
182207
}
183208

184209
func stopBackgroundMonitoring() {
@@ -188,6 +213,7 @@ extension CbfClient {
188213
task.cancel()
189214
if let hb = Self.heartbeatTasks.removeValue(forKey: id) { hb.cancel() }
190215
if let wt = Self.warningTasks.removeValue(forKey: id) { wt.cancel() }
216+
if let lt = Self.logTasks.removeValue(forKey: id) { lt.cancel() }
191217
Self.lastInfoAt.removeValue(forKey: id)
192218
}
193219
}
@@ -196,9 +222,11 @@ extension CbfClient {
196222
Self.monitoringTasksQueue.sync {
197223
for (_, task) in Self.monitoringTasks { task.cancel() }
198224
for (_, wt) in Self.warningTasks { wt.cancel() }
225+
for (_, lt) in Self.logTasks { lt.cancel() }
199226
for (_, hb) in Self.heartbeatTasks { hb.cancel() }
200227
Self.monitoringTasks.removeAll()
201228
Self.warningTasks.removeAll()
229+
Self.logTasks.removeAll()
202230
Self.heartbeatTasks.removeAll()
203231
Self.lastInfoAt.removeAll()
204232
}

0 commit comments

Comments
 (0)