Skip to content

Commit 107bc27

Browse files
committed
[Concurrency] Remove Handle.Failure, since we do not use it as get() is always throwing currently;
There is no meaningful way to restrict the error type (or expect it for that matter.
1 parent 3e26178 commit 107bc27

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extension Task {
9898
/// i.e. the task will run regardless of the handle still being present or not.
9999
/// Dropping a handle however means losing the ability to await on the task's result
100100
/// and losing the ability to cancel it.
101-
public final class Handle<Success, Failure: Error> {
101+
public final class Handle<Success> {
102102
/// Wait for the task to complete, returning (or throwing) its result.
103103
///
104104
/// ### Priority
@@ -107,7 +107,12 @@ extension Task {
107107
/// creating the task with the "right" priority to in the first place.
108108
///
109109
/// ### Cancellation
110-
/// If the awaited on task gets cancelled the `get()` will throw a cancellation error.
110+
/// If the awaited on task gets cancelled externally the `get()` will throw
111+
/// a cancellation error.
112+
///
113+
/// If the task gets cancelled internally, e.g. by checking for cancellation
114+
/// and throwing a specific error or using `checkCancellation` the error
115+
/// thrown out of the task will be re-thrown here.
111116
public func get() async throws -> Success {
112117
fatalError("\(#function) not implemented yet.")
113118
}
@@ -147,21 +152,21 @@ extension Task {
147152
///
148153
/// Canceling a task must be performed explicitly via `handle.cancel()`.
149154
///
150-
/// - Parameters:
151-
/// - priority: priority of the task TODO: reword and define more explicitly once we have priorities well-defined
152-
/// - operation:
153-
/// - Returns: handle to the task, allowing to `await handle.get()` on the
154-
/// tasks result or `cancel` it.
155-
///
156155
/// - Note: it is generally preferable to use child tasks rather than detached
157156
/// tasks. Child tasks automatically carry priorities, task-local state,
158157
/// deadlines and have other benefits resulting from the structured
159158
/// concurrency concepts that they model. Consider using detached tasks only
160159
/// when strictly necessary and impossible to model operations otherwise.
160+
///
161+
/// - Parameters:
162+
/// - priority: priority of the task TODO: reword and define more explicitly once we have priorities well-defined
163+
/// - operation: the operation to execute
164+
/// - Returns: handle to the task, allowing to `await handle.get()` on the
165+
/// tasks result or `cancel` it.
161166
public static func runDetached<T>(
162167
priority: Priority = .default,
163168
operation: () async -> T
164-
) -> Handle<T, Never> {
169+
) -> Handle<T> {
165170
fatalError("\(#function) not implemented yet.")
166171
}
167172

@@ -183,22 +188,22 @@ extension Task {
183188
///
184189
/// Canceling a task must be performed explicitly via `handle.cancel()`.
185190
///
186-
/// - Parameters:
187-
/// - priority: priority of the task TODO: reword and define more explicitly once we have priorities well-defined
188-
/// - operation:
189-
/// - Returns: handle to the task, allowing to `await handle.get()` on the
190-
/// tasks result or `cancel` it. If the operation fails the handle will
191-
/// throw the error the operation has thrown when awaited on.
192-
///
193191
/// - Note: it is generally preferable to use child tasks rather than detached
194192
/// tasks. Child tasks automatically carry priorities, task-local state,
195193
/// deadlines and have other benefits resulting from the structured
196194
/// concurrency concepts that they model. Consider using detached tasks only
197195
/// when strictly necessary and impossible to model operations otherwise.
196+
///
197+
/// - Parameters:
198+
/// - priority: priority of the task TODO: reword and define more explicitly once we have priorities well-defined
199+
/// - operation: the operation to execute
200+
/// - Returns: handle to the task, allowing to `await handle.get()` on the
201+
/// tasks result or `cancel` it. If the operation fails the handle will
202+
/// throw the error the operation has thrown when awaited on.
198203
public static func runDetached<T>(
199204
priority: Priority = .default,
200205
operation: () async throws -> T
201-
) -> Handle<T, Error> {
206+
) -> Handle<T> {
202207
fatalError("\(#function) not implemented yet.")
203208
}
204209
}

test/Concurrency/async_tasks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func test_detached() async throws {
7777
}
7878

7979
func test_detached_throwing() async -> String {
80-
let handle: Task.Handle<String, Error> = Task.runDetached() {
80+
let handle: Task.Handle<String> = Task.runDetached() {
8181
await try someThrowingAsyncFunc() // able to call async functions
8282
}
8383

0 commit comments

Comments
 (0)