Skip to content

Commit 367305b

Browse files
authored
Merge pull request #36919 from ktoso/wip-detach-signature
2 parents c917530 + 5e0593f commit 367305b

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,10 @@ public func detach<T>(
462462
/// throw the error the operation has thrown when awaited on.
463463
@discardableResult
464464
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
465-
public func detach<T, Failure>(
465+
public func detach<T>(
466466
priority: Task.Priority = .unspecified,
467467
operation: __owned @Sendable @escaping () async throws -> T
468-
) -> Task.Handle<T, Failure> {
468+
) -> Task.Handle<T, Error> {
469469
// Set up the job flags for a new task.
470470
var flags = Task.JobFlags()
471471
flags.kind = .task
@@ -478,7 +478,7 @@ public func detach<T, Failure>(
478478
// Enqueue the resulting job.
479479
_enqueueJobGlobal(Builtin.convertTaskToJob(task))
480480

481-
return Task.Handle<T, Failure>(task)
481+
return Task.Handle<T, Error>(task)
482482
}
483483

484484
// ==== Async Handler ----------------------------------------------------------

test/Concurrency/Runtime/async_task_detach.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,42 @@ class X {
1919
}
2020
}
2121

22+
struct Boom: Error {}
23+
2224
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
2325
func test_detach() async {
24-
for _ in 1...3 {
25-
let x = X()
26-
let h = detach {
27-
print("inside: \(x)")
28-
}
29-
await h.get()
26+
let x = X()
27+
let h = detach {
28+
print("inside: \(x)")
3029
}
30+
await h.get()
3131
// CHECK: X: init
3232
// CHECK: inside: main.X
3333
// CHECK: X: deinit
3434
}
3535

36+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
37+
func test_detach_throw() async {
38+
let x = X()
39+
let h = detach {
40+
print("inside: \(x)")
41+
throw Boom()
42+
}
43+
do {
44+
try await h.get()
45+
} catch {
46+
print("error: \(error)")
47+
}
48+
// CHECK: X: init
49+
// CHECK: inside: main.X
50+
// CHECK: error: Boom()
51+
}
52+
3653

3754
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
3855
@main struct Main {
3956
static func main() async {
4057
await test_detach()
58+
await test_detach_throw()
4159
}
4260
}

0 commit comments

Comments
 (0)