import Foundation /// A source of pasteboard poll ticks. Production uses a 120 ms timer; tests drive it manually. public protocol PasteboardTicking: Sendable { /// A stream of ticks. Cancelling the consuming task must terminate the stream. func ticks() -> AsyncStream } /// The production 120 ms ticker (`docs/SELECTION_AND_CLIPBOARD.md` ยง2). public struct TimerPasteboardTicker: PasteboardTicking { /// The poll interval. public let interval: Duration /// Creates a ticker. public init(interval: Duration = .milliseconds(120)) { self.interval = interval } public func ticks() -> AsyncStream { AsyncStream { continuation in let task = Task { while !Task.isCancelled { do { try await Task.sleep(for: interval) } catch { break } continuation.yield(()) } continuation.finish() } continuation.onTermination = { _ in task.cancel() } } } }