Skip to content

Commit 79d45c0

Browse files
Merge pull request swiftlang#38477 from varungandhi-apple/vg-deprecate-old-sleep
[Concurrency] Deprecate Task.sleep(_:) in favor of Task.sleep(nanoseconds:).
2 parents 7bbc29a + 9adc0a5 commit 79d45c0

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

stdlib/public/Concurrency/TaskSleep.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import Swift
1414

1515
@available(SwiftStdlib 5.5, *)
1616
extension Task where Success == Never, Failure == Never {
17-
/// Suspends the current task for _at least_ the given duration
18-
/// in nanoseconds.
19-
///
20-
/// This function does _not_ block the underlying thread.
17+
@available(*, deprecated, renamed: "Task.sleep(nanoseconds:)")
2118
public static func sleep(_ duration: UInt64) async {
2219
return await Builtin.withUnsafeContinuation { (continuation: Builtin.RawUnsafeContinuation) -> Void in
2320
let job = _taskCreateNullaryContinuationJob(

test/Concurrency/async_task_groups.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func asyncThrowsOnCancel() async throws -> Int {
1313
// terrible suspend-spin-loop -- do not do this
1414
// only for purposes of demonstration
1515
while Task.isCancelled {
16-
await Task.sleep(1_000_000_000)
16+
try? await Task.sleep(nanoseconds: 1_000_000_000)
1717
}
1818

1919
throw CancellationError()

0 commit comments

Comments
 (0)