Instance Methodswift 6.0.1_Concurrency
cancelAll
Cancel all of the remaining tasks in the group.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
func cancelAll()
If you add a task to a group after canceling the group, that task is canceled immediately after being added to the group.
Immediately cancelled child tasks should therefore cooperatively check for and react to cancellation, e.g. by throwing an CancellationError
at their earliest convenience, or otherwise handling the cancellation.
There are no restrictions on where you can call this method. Code inside a child task or even another task can cancel a group, however one should be very careful to not keep a reference to the group longer than the with...TaskGroup(...) { ... }
method body is executing.
Other members in extension
Instance members
var isCancelled: Bool
A Boolean value that indicates whether the group was canceled.
var isEmpty: Bool
A Boolean value that indicates whether the group has any remaining tasks.
func addTask(priority: TaskPriority?, operation: sending
Adds a child task to the group.
func addTaskUnlessCancelled(priority: TaskPriority?, operation: sending
Adds a child task to the group, unless the group has been canceled.
func next(
) async throws -> ChildTaskResult? func next(isolation: isolated (any Actor)?
) async throws -> ChildTaskResult? Wait for the next child task to complete, and return the value it returned or rethrow the error it threw.
func nextResult(isolation: isolated (any Actor)?
) async -> Result<ChildTaskResult, Failure>? Wait for the next child task to complete, and return a result containing either the value that the child task returned or the error that it threw.
func waitForAll(isolation: isolated (any Actor)?
) async throws Wait for all of the group’s remaining tasks to complete.