Skip to content

Commit 20c8bd1

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 b7e2136 commit 20c8bd1

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
@@ -333,7 +333,14 @@ public struct TaskGroup<ChildTaskResult> {
333333
internal mutating func awaitAllRemainingTasks() async {
334334
while let _ = await next() {}
335335
}
336-
336+
337+
/// Wait for all remaining tasks in the task group to complete before
338+
/// returning.
339+
@_alwaysEmitIntoClient
340+
public mutating func waitForAll() async {
341+
await awaitAllRemainingTasks()
342+
}
343+
337344
/// Query whether the group has any remaining tasks.
338345
///
339346
/// Task groups are always empty upon entry to the `withTaskGroup` body, and
@@ -424,6 +431,17 @@ public struct ThrowingTaskGroup<ChildTaskResult, Failure: Error> {
424431
}
425432
}
426433

434+
public mutating func _waitForAll() async throws {
435+
while let _ = try await next() { }
436+
}
437+
438+
/// Wait for all remaining tasks in the task group to complete before
439+
/// returning.
440+
@_alwaysEmitIntoClient
441+
public mutating func waitForAll() async throws {
442+
while let _ = try await next() { }
443+
}
444+
427445
/// Spawn, unconditionally, a child task in the group.
428446
///
429447
/// ### Error handling

0 commit comments

Comments
 (0)