Skip to content

Commit 1763dd1

Browse files
committed
[SE-0304] Add (Throwing)?TaskGroup.waitForAll()
Do this as a staged change to the ABI, introducing an underscored `@usableFromInline` implementation to the ABI that we can rely on later, and an `@_alwaysEmitIntoClient` version we can inline now.
1 parent 1b5a8d5 commit 1763dd1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,14 @@ public struct TaskGroup<ChildTaskResult> {
354354
internal mutating func awaitAllRemainingTasks() async {
355355
while let _ = await next() {}
356356
}
357-
357+
358+
/// Wait for all remaining tasks in the task group to complete before
359+
/// returning.
360+
@_alwaysEmitIntoClient
361+
public mutating func waitForAll() async {
362+
await awaitAllRemainingTasks()
363+
}
364+
358365
/// A Boolean value that indicates whether the group has any remaining tasks.
359366
///
360367
/// At the start of the body of a `withTaskGroup(of:returning:body:)` call,
@@ -444,6 +451,17 @@ public struct ThrowingTaskGroup<ChildTaskResult, Failure: Error> {
444451
}
445452
}
446453

454+
public mutating func _waitForAll() async throws {
455+
while let _ = try await next() { }
456+
}
457+
458+
/// Wait for all remaining tasks in the task group to complete before
459+
/// returning.
460+
@_alwaysEmitIntoClient
461+
public mutating func waitForAll() async throws {
462+
while let _ = try await next() { }
463+
}
464+
447465
/// Unconditionally create a child task in the group.
448466
///
449467
/// ### Error handling

0 commit comments

Comments
 (0)