Ahh, @isolated(any) . It’s an attribute of contradictions. You might see it a lot, but it’s ok to ignore it. You don’t need to use it, but I think it should be used more. It must always take an argument, but that argument cannot vary.
Confusing? Definitely. But we’ll get to it all.
To understand why @isolated(any) was introduced, we need to take a look at async functions.
let respond To Emergency : () async -> Void
This is about as simple a function type as we can get. But, things start to get a little more interesting when we look at how a function like this is used. A variable with this type must always be invoked with await .
await respond To Emergency ()
This, of course, makes sense. All async functions must be called with await . But! Consider this:
let send Ambulance : @Main Actor () -> Void = { print ( "🚑 WEE-OOO WEE-OOO!" ) } let respond To Emergency : () async -> Void = send Ambulance await respond To Emergency ()
The explicit types are there to help make what’s going on clear. We first define a synchronous function that must run on the Main Actor . And then we assign that to a plain old, non- Main Actor async function. We’ve changed so much that you might find it surprising this even compiles.
Remember what await actually does. It allows the current task to suspend. That doesn’t just let the task wait for future work to complete. It also is an opportunity to change isolation. This makes async functions very flexible!
... continue reading