@@ -122,7 +122,7 @@ public func withDiscardingTaskGroup<GroupResult>(
122
122
/// - when an error is thrown out of the `withThrowingDiscardingTaskGroup(...) { }` closure,
123
123
/// - when the ``Task`` running this task group is cancelled.
124
124
///
125
- /// Since a `TaskGroup ` is a structured concurrency primitive, cancellation is
125
+ /// Since a `DiscardingTaskGroup ` is a structured concurrency primitive, cancellation is
126
126
/// automatically propagated through all of its child-tasks (and their child
127
127
/// tasks).
128
128
///
@@ -161,6 +161,13 @@ public struct DiscardingTaskGroup {
161
161
let _: Void ? = try await _taskGroupWaitAll ( group: _group, bodyError: nil )
162
162
}
163
163
164
+ /// Adds a child task to the group.
165
+ ///
166
+ /// - Parameters:
167
+ /// - priority: The priority of the operation task.
168
+ /// Omit this parameter or pass `.unspecified`
169
+ /// to set the child task's priority to the priority of the group.
170
+ /// - operation: The operation to execute as part of the task group.
164
171
@_alwaysEmitIntoClient
165
172
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
166
173
@available ( * , unavailable, message: " Unavailable in task-to-thread concurrency model " , renamed: " addTask(operation:) " )
@@ -187,6 +194,15 @@ public struct DiscardingTaskGroup {
187
194
_ = Builtin . createAsyncTaskInGroup ( flags, _group, operation)
188
195
}
189
196
197
+ /// Adds a child task to the group, unless the group has been canceled.
198
+ ///
199
+ /// - Parameters:
200
+ /// - priority: The priority of the operation task.
201
+ /// Omit this parameter or pass `.unspecified`
202
+ /// to set the child task's priority to the priority of the group.
203
+ /// - operation: The operation to execute as part of the task group.
204
+ /// - Returns: `true` if the child task was added to the group;
205
+ /// otherwise `false`.
190
206
@_alwaysEmitIntoClient
191
207
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
192
208
@available ( * , unavailable, message: " Unavailable in task-to-thread concurrency model " , renamed: " addTask(operation:) " )
@@ -235,6 +251,12 @@ public struct DiscardingTaskGroup {
235
251
_ = Builtin . createAsyncTaskInGroup ( flags, _group, operation)
236
252
}
237
253
254
+ /// Adds a child task to the group, unless the group has been canceled.
255
+ ///
256
+ /// - Parameters:
257
+ /// - operation: The operation to execute as part of the task group.
258
+ /// - Returns: `true` if the child task was added to the group;
259
+ /// otherwise `false`.
238
260
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
239
261
@available ( * , unavailable, message: " Unavailable in task-to-thread concurrency model " , renamed: " addTaskUnlessCancelled(operation:) " )
240
262
#endif
@@ -265,14 +287,46 @@ public struct DiscardingTaskGroup {
265
287
#endif
266
288
}
267
289
290
+ /// A Boolean value that indicates whether the group has any remaining tasks.
291
+ ///
292
+ /// At the start of the body of a `withDiscardingTaskGroup(of:returning:body:)` call,
293
+ /// the task group is always empty.
294
+ ///
295
+ /// It's guaranteed to be empty when returning from that body
296
+ /// because a task group waits for all child tasks to complete before returning.
297
+ ///
298
+ /// - Returns: `true` if the group has no pending tasks; otherwise `false`.
268
299
public var isEmpty : Bool {
269
300
_taskGroupIsEmpty ( _group)
270
301
}
271
302
303
+ /// Cancel all of the remaining tasks in the group.
304
+ ///
305
+ /// If you add a task to a group after canceling the group,
306
+ /// that task is canceled immediately after being added to the group.
307
+ ///
308
+ /// Immediately cancelled child tasks should therefore cooperatively check for and
309
+ /// react to cancellation, e.g. by throwing an `CancellationError` at their
310
+ /// earliest convenience, or otherwise handling the cancellation.
311
+ ///
312
+ /// There are no restrictions on where you can call this method.
313
+ /// Code inside a child task or even another task can cancel a group,
314
+ /// however one should be very careful to not keep a reference to the
315
+ /// group longer than the `with...TaskGroup(...) { ... }` method body is executing.
316
+ ///
317
+ /// - SeeAlso: `Task.isCancelled`
318
+ /// - SeeAlso: `DiscardingTaskGroup.isCancelled`
272
319
public func cancelAll( ) {
273
320
_taskGroupCancelAll ( group: _group)
274
321
}
275
322
323
+ /// A Boolean value that indicates whether the group was canceled.
324
+ ///
325
+ /// To cancel a group, call the `DiscardingTaskGroup.cancelAll()` method.
326
+ ///
327
+ /// If the task that's currently running this group is canceled,
328
+ /// the group is also implicitly canceled,
329
+ /// which is also reflected in this property's value.
276
330
public var isCancelled : Bool {
277
331
return _taskGroupIsCancelled ( group: _group)
278
332
}
@@ -575,7 +629,7 @@ public struct ThrowingDiscardingTaskGroup<Failure: Error> {
575
629
/// group longer than the `with...TaskGroup(...) { ... }` method body is executing.
576
630
///
577
631
/// - SeeAlso: `Task.isCancelled`
578
- /// - SeeAlso: `ThrowingTaskGroup .isCancelled`
632
+ /// - SeeAlso: `ThrowingDiscardingTaskGroup .isCancelled`
579
633
public func cancelAll( ) {
580
634
_taskGroupCancelAll ( group: _group)
581
635
}
0 commit comments