I just tried the same API with TaskGroup
instead of Task
:
func newSend(
operation: sending @escaping @isolated(any) () async -> Void
) async {
await withTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask { // error: Task-isolated value of type '() async -> Void' passed as a strongly transferred parameter; later accesses could race
await operation()
}
}
}
func oldSend(
operation: @escaping @Sendable () async -> Void
) async {
await withTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
await operation()
}
}
}
This does not work, somehow.
This compiler message was mentioned here Feedback wanted: confusing concurrency diagnostic messages - #12 by twof as being unclear, but it does not seem to be clearer by now...