Skip to content

Commit 39180ad

Browse files
committed
Move CancellationError out to the top level
(cherry picked from commit fdee0ff)
1 parent a7eed56 commit 39180ad

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

stdlib/public/Concurrency/SourceCompatibilityShims.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ import Swift
1818

1919
@available(SwiftStdlib 5.5, *)
2020
extension Task where Success == Never, Failure == Never {
21-
@available(*, deprecated, message: "use TaskPriority")
21+
@available(*, deprecated, message: "Task.Priority has been removed; use TaskPriority")
2222
public typealias Priority = TaskPriority
2323

24-
@available(*, deprecated, message: "use Task")
24+
@available(*, deprecated, message: "Task.Handle has been removed; use Task")
2525
public typealias Handle = _Concurrency.Task
26+
27+
@available(*, deprecated, message: "Task.CancellationError has been removed; use CancellationError")
28+
@_alwaysEmitIntoClient
29+
public static func CancellationError() -> _Concurrency.CancellationError {
30+
return _Concurrency.CancellationError()
31+
}
2632
}
2733

2834
@available(SwiftStdlib 5.5, *)

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,16 @@ extension Task where Success == Never, Failure == Never {
8989
throw CancellationError()
9090
}
9191
}
92+
}
9293

93-
/// The default cancellation thrown when a task is cancelled.
94-
///
95-
/// The `Task.checkCancellation()` method throws this error
96-
/// if the current task has been canceled.
97-
/// You can throw this error in your cancellation-checking code,
98-
/// or another more specific error if needed.
99-
public struct CancellationError: Error {
100-
// no extra information, cancellation is intended to be light-weight
101-
public init() {}
102-
}
94+
/// The default cancellation thrown when a task is cancelled.
95+
///
96+
/// This error is also thrown automatically by `Task.checkCancellation()`,
97+
/// if the current task has been cancelled.
98+
@available(SwiftStdlib 5.5, *)
99+
public struct CancellationError: Error {
100+
// no extra information, cancellation is intended to be light-weight
101+
public init() {}
103102
}
104103

105104
@available(SwiftStdlib 5.5, *)

test/Concurrency/async_task_groups.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func asyncThrowsOnCancel() async throws -> Int {
1616
await Task.sleep(1_000_000_000)
1717
}
1818

19-
throw Task.CancellationError()
19+
throw CancellationError()
2020
}
2121

2222
@available(SwiftStdlib 5.5, *)

0 commit comments

Comments
 (0)