Run Actor Run
There is a technique that is useful 1 when converting apps to Swift Concurrency.
Fire off work to another actor and wait for it to complete
It is provided for MainActor, but isn’t available on actors you create yourself.
Not fair!
I dug around and found a way to make this available on custom actors.
Extension
This is an extension that will allow a Global Actor to initiate a run command similar to MainActor. I took the signature from the MainActor definition itself.
This allows us to use the run func in the same way MainActor does.
This shouldn’t be heavily used. Although it can be tempting, there is almost always a better way to get similar behavior. But I’ve seen this solve a number of issues devs have faced in legacy code.
-
This is frequently a bad idea. But can be appropriate in some cases. ↩