Some comments on the syntax in this example:
func delay(operation: @isolated(any) () -> ()) {
let isolation = operation.isolation
Task { [isolated isolation] in
print("waking")
operation() // <-- does not cross an isolation barrier and so is synchronous
print("finished")
}
}
It's really great that this will be possible!
Could it make sense to also use the @isolated annotation to support applying an explicit isolation to a closure? That could let us simplify this example to:
func delay(operation: @isolated(any) () -> ()) {
Task { @isolated(operation) in // seems very elegant!
// ...
}
}
I find this spelling really appealing because it's more similar to the syntax for isolating a closure to a global actor (both would use an @ annotation: @MainActor in and @isolated(myActor) in).
e.g. in this example from earlier, I'd find @isolated(counter) to be more intuitive and appealing:
vs
Task { @isolated(counter) in
counter.incrementAndAssertCountEquals(iteration)
}