@@ -133,18 +133,18 @@ extension Task where Success == Never, Failure == Never {
133
133
///
134
134
/// This function doesn't block the underlying thread.
135
135
///
136
- /// try await Task.sleep(until: .now + .seconds(3), clock: .continuous )
136
+ /// try await Task.sleep(until: .now + .seconds(3))
137
137
///
138
138
@available ( SwiftStdlib 5 . 7 , * )
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
}
146
146
147
- /// Suspends the current task for the given duration on a continuous clock .
147
+ /// Suspends the current task for the given duration.
148
148
///
149
149
/// If the task is cancelled before the time ends, this function throws
150
150
/// `CancellationError`.
@@ -153,11 +153,14 @@ extension Task where Success == Never, Failure == Never {
153
153
///
154
154
/// try await Task.sleep(for: .seconds(3))
155
155
///
156
- /// - Parameter duration: The duration to wait.
157
156
@available ( SwiftStdlib 5 . 7 , * )
158
157
@_alwaysEmitIntoClient
159
- public static func sleep( for duration: Duration ) async throws {
160
- try await sleep ( until: . now + duration, clock: . continuous)
158
+ public static func sleep< C: Clock > (
159
+ for duration: C . Instant . Duration ,
160
+ tolerance: C . Instant . Duration ? = nil ,
161
+ clock: C = ContinuousClock ( )
162
+ ) async throws {
163
+ try await clock. sleep ( for: duration, tolerance: tolerance)
161
164
}
162
165
}
163
166
#else
@@ -169,13 +172,18 @@ extension Task where Success == Never, Failure == Never {
169
172
public static func sleep< C: Clock > (
170
173
until deadline: C . Instant ,
171
174
tolerance: C . Instant . Duration ? = nil ,
172
- clock: C
175
+ clock: C = ContinuousClock ( )
173
176
) async throws {
174
177
fatalError ( " Unavailable in task-to-thread concurrency model " )
175
178
}
176
179
@available ( SwiftStdlib 5 . 7 , * )
177
180
@available ( * , unavailable, message: " Unavailable in task-to-thread concurrency model " )
178
- public static func sleep( for duration: Duration ) async throws {
181
+ @_alwaysEmitIntoClient
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