Hello,
recently, I've been experimenting with some uses cases with TaskGroups. One problem that bites me quite often, is the following:
func send(
operation: sending @escaping () async -> Void
) async {
await withTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask { // error: passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure
await operation()
}
}
}
I've mentioned this is in past threads and also reported this as bug in Github already. However, this has been in several Swift versions (6.0 -> today's nightly), so I am not so sure anymore if this is an actual bug or something to be expected/not working (yet).
From my (maybe too limited) understanding of this topic, is, that operation is being sent once to the isolation domain of the withTaskGroups body and another time into the isolation domain of addTask. In reality, this should actually be fine, no? I am not using operation in any other context other than in addTask, so it should not be required to be @Sendable.
The error message changed comparing recent releases of Swift and nightly builds, however I am still not sure, if I fully understand it and can relate it to my code. Would someone mind help me understand the problem here?
Thank you.