@@ -15,6 +15,10 @@ import Swift
15
15
@available ( SwiftStdlib 5 . 1 , * )
16
16
extension Task where Success == Never , Failure == Never {
17
17
@available ( * , deprecated, renamed: " Task.sleep(nanoseconds:) " )
18
+ /// Suspends the current task for at least the given duration
19
+ /// in nanoseconds.
20
+ ///
21
+ /// This function doesn't block the underlying thread.
18
22
public static func sleep( _ duration: UInt64 ) async {
19
23
return await Builtin . withUnsafeContinuation { ( continuation: Builtin . RawUnsafeContinuation ) -> Void in
20
24
let job = _taskCreateNullaryContinuationJob (
@@ -39,10 +43,10 @@ extension Task where Success == Never, Failure == Never {
39
43
/// The sleep has finished.
40
44
case finished
41
45
42
- /// The sleep was cancelled .
46
+ /// The sleep was canceled .
43
47
case cancelled
44
48
45
- /// The sleep was cancelled before it even got started.
49
+ /// The sleep was canceled before it even got started.
46
50
case cancelledBeforeStarted
47
51
48
52
/// Decode sleep state from the word of storage.
@@ -100,7 +104,7 @@ extension Task where Success == Never, Failure == Never {
100
104
}
101
105
102
106
/// Called when the sleep(nanoseconds:) operation woke up without being
103
- /// cancelled .
107
+ /// canceled .
104
108
private static func onSleepWake(
105
109
_ wordPtr: UnsafeMutablePointer < Builtin . Word >
106
110
) {
@@ -143,7 +147,7 @@ extension Task where Success == Never, Failure == Never {
143
147
}
144
148
}
145
149
146
- /// Called when the sleep(nanoseconds:) operation has been cancelled before
150
+ /// Called when the sleep(nanoseconds:) operation has been canceled before
147
151
/// the sleep completed.
148
152
private static func onSleepCancel(
149
153
_ wordPtr: UnsafeMutablePointer < Builtin . Word >
@@ -189,11 +193,13 @@ extension Task where Success == Never, Failure == Never {
189
193
}
190
194
}
191
195
192
- /// Suspends the current task for _at least_ the given duration
193
- /// in nanoseconds, unless the task is cancelled. If the task is cancelled,
194
- /// throws \c CancellationError without waiting for the duration.
196
+ /// Suspends the current task for at least the given duration
197
+ /// in nanoseconds.
198
+ ///
199
+ /// If the task is canceled before the time ends,
200
+ /// this function throws `CancellationError`.
195
201
///
196
- /// This function does _not_ block the underlying thread.
202
+ /// This function doesn't block the underlying thread.
197
203
public static func sleep( nanoseconds duration: UInt64 ) async throws {
198
204
// Allocate storage for the storage word.
199
205
let wordPtr = UnsafeMutablePointer< Builtin . Word> . allocate( capacity: 1 )
0 commit comments