Skip to content

Commit 9949bf4

Browse files
committed
updated to latest Task APIs
1 parent fde8098 commit 9949bf4

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ extension Task {
504504
}
505505

506506
// ==== Voluntary Suspension -----------------------------------------------------
507+
508+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
507509
extension Task {
508510

509511
/// Explicitly suspend the current task, potentially giving up execution actor

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ extension TaskGroup: AsyncSequence {
708708
/// - SeeAlso: `TaskGroup.next()` for a detailed discussion its semantics.
709709
public mutating func next() async -> Element? {
710710
guard !finished else { return nil }
711-
guard let element = try await group.next() else {
711+
guard let element = await group.next() else {
712712
finished = true
713713
return nil
714714
}

test/Concurrency/Runtime/async_task_yield.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
// REQUIRES: executable_test
44
// REQUIRES: concurrency
55

6+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
67
protocol Go: Actor {
78
func go(times: Int) async -> Int
89
}
10+
11+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
912
extension Go {
1013
func go(times: Int) async -> Int {
1114
for i in 0...times {
@@ -16,22 +19,26 @@ extension Go {
1619
}
1720
}
1821

22+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
1923
actor One: Go {}
24+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
2025
actor Two: Go {}
2126

27+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
2228
func yielding() async {
2329
let one = One()
2430
let two = Two()
25-
try! await Task.withGroup(resultType: Int.self) { group in
26-
await group.add {
31+
await withTaskGroup(of: Int.self) { group in
32+
await group.spawn {
2733
await one.go(times: 100)
2834
}
29-
await group.add {
35+
await group.spawn {
3036
await two.go(times: 100)
3137
}
3238
}
3339
}
3440

41+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
3542
@main struct Main {
3643
static func main() async {
3744
await yielding()

0 commit comments

Comments
 (0)