The rule is that closures passed to the primary Task initializer[1] from an isolated context inherit that isolation. Currently there is an exception that this does not happen when the outer context is actor-isolated and the closure doesn't capture that actor, but we've discussed removing that exception because it's quite confusing in practice.


  1. in general: when a closure expression is used directly as the argument for an @_inheritsActorContext parameter; but that is not an official feature, and proposal documents always talk about Task.init ↩︎

3 Likes