@@ -139,7 +139,7 @@ extension Task where Success == Never, Failure == Never {
139
139
public static func sleep< C: Clock > (
140
140
until deadline: C . Instant ,
141
141
tolerance: C . Instant . Duration ? = nil ,
142
- clock: C
142
+ clock: C = ContinuousClock ( )
143
143
) async throws {
144
144
try await clock. sleep ( until: deadline, tolerance: tolerance)
145
145
}
@@ -156,8 +156,12 @@ extension Task where Success == Never, Failure == Never {
156
156
/// - Parameter duration: The duration to wait.
157
157
@available ( SwiftStdlib 5 . 7 , * )
158
158
@_alwaysEmitIntoClient
159
- public static func sleep( for duration: Duration ) async throws {
160
- try await sleep ( until: . now + duration, clock: . continuous)
159
+ public static func sleep< C: Clock > (
160
+ for duration: C . Instant . Duration ,
161
+ tolerance: C . Instant . Duration ? = nil ,
162
+ clock: C = ContinuousClock ( )
163
+ ) async throws {
164
+ try await sleep ( until: clock. now. advanced ( by: duration) , tolerance: tolerance, clock: clock)
161
165
}
162
166
}
163
167
#else
@@ -169,13 +173,17 @@ extension Task where Success == Never, Failure == Never {
169
173
public static func sleep< C: Clock > (
170
174
until deadline: C . Instant ,
171
175
tolerance: C . Instant . Duration ? = nil ,
172
- clock: C
176
+ clock: C = ContinuousClock ( )
173
177
) async throws {
174
178
fatalError ( " Unavailable in task-to-thread concurrency model " )
175
179
}
176
180
@available ( SwiftStdlib 5 . 7 , * )
177
181
@available ( * , unavailable, message: " Unavailable in task-to-thread concurrency model " )
178
- public static func sleep( for duration: Duration ) async throws {
182
+ public static func sleep< C: Clock > (
183
+ for duration: C . Instant . Duration ,
184
+ tolerance: C . Instant . Duration ? = nil ,
185
+ clock: C = ContinuousClock ( )
186
+ ) async throws {
179
187
fatalError ( " Unavailable in task-to-thread concurrency model " )
180
188
}
181
189
}
0 commit comments