17 lines
509 B
Swift
17 lines
509 B
Swift
import Foundation
|
|
|
|
public nonisolated struct MetricsClock: Sendable {
|
|
public var now: @Sendable () -> Date = { Date() }
|
|
public var sleep: @Sendable (TimeInterval) async throws -> Void = {
|
|
try await Task.sleep(for: .seconds($0))
|
|
}
|
|
public init(
|
|
now: @escaping @Sendable () -> Date = { Date() },
|
|
sleep: @escaping @Sendable (TimeInterval) async throws -> Void = { try await Task.sleep(for: .seconds($0)) }
|
|
) {
|
|
self.now = now
|
|
self.sleep = sleep
|
|
}
|
|
|
|
}
|