@@ -9,43 +9,10 @@ import Clocks
99import ConcurrencyExtras
1010import Foundation
1111
12- package protocol _Clock : Sendable {
13- func sleep( for duration: TimeInterval ) async throws
14- }
15-
16- @available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
17- extension ContinuousClock : _Clock {
18- package func sleep( for duration: TimeInterval ) async throws {
19- try await sleep ( for: . seconds( duration) )
20- }
21- }
22- @available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
23- extension TestClock < Duration > : _Clock {
24- package func sleep( for duration: TimeInterval ) async throws {
25- try await sleep ( for: . seconds( duration) )
26- }
27- }
28-
29- /// `_Clock` used on platforms where ``Clock`` protocol isn't available.
30- struct FallbackClock : _Clock {
31- func sleep( for duration: TimeInterval ) async throws {
32- try await Task . sleep ( nanoseconds: NSEC_PER_SEC * UInt64( duration) )
33- }
34- }
35-
36- // Resolves clock instance based on platform availability.
37- let _resolveClock : @Sendable ( ) -> any _Clock = {
38- if #available( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * ) {
39- ContinuousClock ( )
40- } else {
41- FallbackClock ( )
42- }
43- }
44-
45- private let __clock = LockIsolated ( _resolveClock ( ) )
12+ private let __clock : LockIsolated < any Clock < Duration > > = LockIsolated ( ContinuousClock ( ) )
4613
4714#if DEBUG
48- package var _clock : any _Clock {
15+ package var _clock : any Clock < Duration > {
4916 get {
5017 __clock. value
5118 }
@@ -54,7 +21,7 @@ private let __clock = LockIsolated(_resolveClock())
5421 }
5522 }
5623#else
57- package var _clock : any _Clock {
24+ package var _clock : any Clock < Duration > {
5825 __clock. value
5926 }
6027#endif
0 commit comments