An abbreviated version of my function:
@MainActor
func myThing() async throws
{
try await withThrowingTaskGroup(of: Void.self) {
(taskGroup) in
// add some things to the group
try await taskGroup.waitForAll()
}
}
On the waitForAll() call, I get this warning:
Passing argument of non-sendable type 'inout ThrowingTaskGroup<Void, any Error>' outside of main actor-isolated context may introduce data races
I'm guessing what's going on is 1) the closure I pass to withThrowingTaskGroup() inherits @MainActor from the function (this is good for my actual "do the work" part), and 2) waitForAll() is not MainActor isolated, so by calling it I'm effectively passing the non-Sendable task group out of the MainActor context.
Since I'm not supposed to send the task group outside of the task where it was created, how do I call waitForAll() without doing that?
ktoso
(Konrad 'ktoso' Malawski 🐟🏴☠️)
2
Please state your configuration (swift version etc) when reporting such, it makes things easier to check 
On that specific one, this was fixed recently by having the method accept in isolation parameter:
public mutating func waitForAll(isolation: isolated (any Actor)? = #isolation) async {
I’m not at a computer anymore today to check if this was in beta 1 already or not though.
Id expect this to work with new beta and sdk releases.
1 Like
Jon_Shier
(Jon Shier)
3
Yes, it appears beta 1 has the updated signature.
1 Like
Good point. I'm using Xcode 15.4, so I believe it's Swift 5.10.
1 Like