Add logging to PostponingBlock.
This commit is contained in:
parent
a8f952b710
commit
96fefbc800
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
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`.
|
/// 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 {
|
@MainActor public final class PostponingBlock {
|
||||||
@ -15,6 +16,8 @@ import Foundation
|
|||||||
private let name: String // For debugging
|
private let name: String // For debugging
|
||||||
private var timer: Timer?
|
private var timer: Timer?
|
||||||
|
|
||||||
|
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "PostponingBlock")
|
||||||
|
|
||||||
public init(delayInterval: TimeInterval, name: String, block: @escaping () -> Void) {
|
public init(delayInterval: TimeInterval, name: String, block: @escaping () -> Void) {
|
||||||
|
|
||||||
self.delayInterval = delayInterval
|
self.delayInterval = delayInterval
|
||||||
@ -47,6 +50,7 @@ private extension PostponingBlock {
|
|||||||
|
|
||||||
if let timer, timer.isValid {
|
if let timer, timer.isValid {
|
||||||
timer.invalidate()
|
timer.invalidate()
|
||||||
|
logger.info("Canceling existing timer in PostponingBlock: \(self.name)")
|
||||||
}
|
}
|
||||||
timer = nil
|
timer = nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user