@@ -80,6 +80,7 @@ public func withTaskGroup<ChildTaskResult, GroupResult>(
80
80
// Run the withTaskGroup body.
81
81
let result = await body ( & group)
82
82
83
+ // TODO(concurrency): should get isolation from param from withThrowingTaskGroup
83
84
await group. awaitAllRemainingTasks ( )
84
85
85
86
Builtin . destroyTaskGroup ( _group)
@@ -183,13 +184,15 @@ public func withThrowingTaskGroup<ChildTaskResult, GroupResult>(
183
184
// Run the withTaskGroup body.
184
185
let result = try await body ( & group)
185
186
187
+ // TODO(concurrency): should get isolation from param from withThrowingTaskGroup
186
188
await group. awaitAllRemainingTasks ( )
187
189
Builtin . destroyTaskGroup ( _group)
188
190
189
191
return result
190
192
} catch {
191
193
group. cancelAll ( )
192
194
195
+ // TODO(concurrency): should get isolation from param from withThrowingTaskGroup
193
196
await group. awaitAllRemainingTasks ( )
194
197
Builtin . destroyTaskGroup ( _group)
195
198
@@ -563,22 +566,41 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
563
566
/// that method can't be called from a concurrent execution context like a child task.
564
567
///
565
568
/// - Returns: The value returned by the next child task that completes.
566
- public mutating func next( ) async -> ChildTaskResult ? {
569
+ @available ( SwiftStdlib 5 . 1 , * )
570
+ @backDeployed ( before: SwiftStdlib 6.0 )
571
+ public mutating func next( isolation: isolated ( any Actor ) ? = #isolation) async -> ChildTaskResult ? {
572
+ // try!-safe because this function only exists for Failure == Never,
573
+ // and as such, it is impossible to spawn a throwing child task.
574
+ return try ! await _taskGroupWaitNext ( group: _group) // !-safe cannot throw, we're a non-throwing TaskGroup
575
+ }
576
+
577
+ @usableFromInline
578
+ @available ( SwiftStdlib 5 . 1 , * )
579
+ @_silgen_name ( " $sScG4nextxSgyYaF " )
580
+ internal mutating func __abi_next( ) async -> ChildTaskResult ? {
567
581
// try!-safe because this function only exists for Failure == Never,
568
582
// and as such, it is impossible to spawn a throwing child task.
569
583
return try ! await _taskGroupWaitNext ( group: _group) // !-safe cannot throw, we're a non-throwing TaskGroup
570
584
}
571
585
572
586
/// Await all of the pending tasks added this group.
573
587
@usableFromInline
588
+ @available ( SwiftStdlib 5 . 1 , * )
589
+ @backDeployed ( before: SwiftStdlib 6.0 )
590
+ internal mutating func awaitAllRemainingTasks( isolation: isolated ( any Actor ) ? = #isolation) async {
591
+ while let _ = await next ( isolation: isolation) { }
592
+ }
593
+
594
+ @usableFromInline
595
+ @available ( SwiftStdlib 5 . 1 , * )
574
596
internal mutating func awaitAllRemainingTasks( ) async {
575
- while let _ = await next ( ) { }
597
+ while let _ = await next ( isolation : nil ) { }
576
598
}
577
599
578
600
/// Wait for all of the group's remaining tasks to complete.
579
601
@_alwaysEmitIntoClient
580
- public mutating func waitForAll( ) async {
581
- await awaitAllRemainingTasks ( )
602
+ public mutating func waitForAll( isolation : isolated ( any Actor ) ? = #isolation ) async {
603
+ await awaitAllRemainingTasks ( isolation : isolation )
582
604
}
583
605
584
606
/// A Boolean value that indicates whether the group has any remaining tasks.
@@ -703,16 +725,24 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
703
725
704
726
/// Await all the remaining tasks on this group.
705
727
@usableFromInline
706
- internal mutating func awaitAllRemainingTasks( ) async {
728
+ @available ( SwiftStdlib 5 . 1 , * )
729
+ @backDeployed ( before: SwiftStdlib 6.0 )
730
+ internal mutating func awaitAllRemainingTasks( isolation: isolated ( any Actor ) ? = #isolation) async {
707
731
while true {
708
732
do {
709
- guard let _ = try await next ( ) else {
733
+ guard let _ = try await next ( isolation : isolation ) else {
710
734
return
711
735
}
712
736
} catch { }
713
737
}
714
738
}
715
739
740
+ @usableFromInline
741
+ @available ( SwiftStdlib 5 . 1 , * )
742
+ internal mutating func awaitAllRemainingTasks( ) async {
743
+ await awaitAllRemainingTasks ( isolation: nil )
744
+ }
745
+
716
746
@usableFromInline
717
747
internal mutating func _waitForAll( ) async throws {
718
748
await self . awaitAllRemainingTasks ( )
@@ -750,7 +780,7 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
750
780
/// - Throws: The *first* error that was thrown by a child task during draining all the tasks.
751
781
/// This first error is stored until all other tasks have completed, and is re-thrown afterwards.
752
782
@_alwaysEmitIntoClient
753
- public mutating func waitForAll( ) async throws {
783
+ public mutating func waitForAll( isolation : isolated ( any Actor ) ? = #isolation ) async throws {
754
784
var firstError : Error ? = nil
755
785
756
786
// Make sure we loop until all child tasks have completed
@@ -999,7 +1029,16 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
999
1029
/// - Throws: The error thrown by the next child task that completes.
1000
1030
///
1001
1031
/// - SeeAlso: `nextResult()`
1002
- public mutating func next( ) async throws -> ChildTaskResult ? {
1032
+ @available ( SwiftStdlib 5 . 1 , * )
1033
+ @backDeployed ( before: SwiftStdlib 6.0 )
1034
+ public mutating func next( isolation: isolated ( any Actor ) ? = #isolation) async throws -> ChildTaskResult ? {
1035
+ return try await _taskGroupWaitNext ( group: _group)
1036
+ }
1037
+
1038
+ @usableFromInline
1039
+ @available ( SwiftStdlib 5 . 1 , * )
1040
+ @_silgen_name ( " $sScg4nextxSgyYaKF " )
1041
+ internal mutating func __abi_next( ) async throws -> ChildTaskResult ? {
1003
1042
return try await _taskGroupWaitNext ( group: _group)
1004
1043
}
1005
1044
@@ -1052,7 +1091,7 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
1052
1091
///
1053
1092
/// - SeeAlso: `next()`
1054
1093
@_alwaysEmitIntoClient
1055
- public mutating func nextResult( ) async -> Result < ChildTaskResult , Failure > ? {
1094
+ public mutating func nextResult( isolation : isolated ( any Actor ) ? = #isolation ) async -> Result < ChildTaskResult , Failure > ? {
1056
1095
return try ! await nextResultForABI ( )
1057
1096
}
1058
1097
@@ -1332,7 +1371,7 @@ func _taskGroupIsCancelled(group: Builtin.RawPointer) -> Bool
1332
1371
1333
1372
@available ( SwiftStdlib 5 . 1 , * )
1334
1373
@_silgen_name ( " swift_taskGroup_wait_next_throwing " )
1335
- func _taskGroupWaitNext < T > ( group: Builtin . RawPointer ) async throws -> T ?
1374
+ public func _taskGroupWaitNext< T > ( group: Builtin . RawPointer ) async throws -> T ?
1336
1375
1337
1376
@available ( SwiftStdlib 5 . 1 , * )
1338
1377
@_silgen_name ( " swift_task_hasTaskGroupStatusRecord " )
0 commit comments