Skip to content

Commit b5fd2a5

Browse files
committed
Address review comments; get() must throw, formatting
1 parent 579c89c commit b5fd2a5

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension Task {
3737
/// it is always able to return the current `Task` in which we are currently
3838
/// running.
3939
public static func current() async -> Task {
40-
fatalError("\(#function) not implemented yet.")
40+
fatalError("\(#function) not implemented yet.") // TODO: needs a built-in function
4141
}
4242
}
4343

@@ -100,13 +100,16 @@ extension Task {
100100
/// Dropping a handle however means losing the ability to await on the task's result
101101
/// and losing the ability to cancel it.
102102
public final class Handle<Success, Failure: Error> {
103-
/// Wait for the task to complete, returning (or throwing) its result.
104-
///
105-
/// ### Priority
106-
/// If the task has not completed yet, its priority will be elevated to the
107-
/// priority of the current task. Note that this may not be as effective as
108-
/// creating the task with the "right" priority to in the first place.
109-
public func get() async throws -> Success {
103+
/// Wait for the task to complete, returning (or throwing) its result.
104+
///
105+
/// ### Priority
106+
/// If the task has not completed yet, its priority will be elevated to the
107+
/// priority of the current task. Note that this may not be as effective as
108+
/// creating the task with the "right" priority to in the first place.
109+
///
110+
/// ### Cancellation
111+
/// If the awaited on task gets cancelled the `get()` will throw a cancellation error.
112+
public func get() async throws -> Success {
110113
fatalError("\(#function) not implemented yet.")
111114
}
112115

@@ -124,18 +127,6 @@ extension Task {
124127
}
125128
}
126129

127-
extension Task.Handle where Failure == Never {
128-
/// Wait for the task to complete, returning its result.
129-
///
130-
/// ### Priority
131-
/// If the task has not completed yet, its priority will be elevated to the
132-
/// priority of the current task. Note that this may not be as effective as
133-
/// creating the task with the "right" priority to in the first place.
134-
public func get() async -> Success {
135-
fatalError("\(#function) not implemented yet.")
136-
}
137-
}
138-
139130
// ==== Detached Tasks ---------------------------------------------------------
140131

141132
extension Task {

test/Concurrency/async_tasks.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ func someAsyncFunc() async -> String { "" }
66
struct MyError: Error {}
77
func someThrowingAsyncFunc() async throws -> String { throw MyError() }
88

9-
// non-async function with "weird shape" representing some API that has not adopted
10-
// swift concurrency yet, but we want to call it from an async function and make it
11-
// play nice with the rest of the system.
12-
func someManyCallbacksFunction(
13-
calledSometimes: () -> (),
14-
otherwiseThisIsCalled: () -> (),
15-
calledOnError: (Error) -> ()
16-
) { }
17-
189
func test_unsafeContinuations() async {
1910
// the closure should not allow async operations;
2011
// after all: if you have async code, just call it directly, without the unsafe continuation
@@ -42,12 +33,12 @@ func test_unsafeThrowingContinuations() async {
4233

4334
// ==== Detached Tasks ---------------------------------------------------------
4435

45-
func test_detached() async {
36+
func test_detached() async throws {
4637
let handle = Task.runDetached() {
4738
await someAsyncFunc() // able to call async functions
4839
}
4940

50-
let result: String = await handle.get()
41+
let result: String = await try handle.get()
5142
_ = result
5243
}
5344

0 commit comments

Comments
 (0)