Add logging to PostponingBlock.

This commit is contained in:
Brent Simmons 2024-06-09 22:39:36 -07:00
parent a8f952b710
commit 96fefbc800

View File

@ -6,6 +6,7 @@
//
import Foundation
import os
/// Runs a block of code in the future. Each time `runInFuture` is called, the block is postponed again until the future by `delayInterval`.
@MainActor public final class PostponingBlock {
@ -15,6 +16,8 @@ import Foundation
private let name: String // For debugging
private var timer: Timer?
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "PostponingBlock")
public init(delayInterval: TimeInterval, name: String, block: @escaping () -> Void) {
self.delayInterval = delayInterval
@ -47,6 +50,7 @@ private extension PostponingBlock {
if let timer, timer.isValid {
timer.invalidate()
logger.info("Canceling existing timer in PostponingBlock: \(self.name)")
}
timer = nil
}