I am currently in the process of converting one of the singletons in my app, a class which manages a specific global state, to an actor, specifically a global actor. For the sake of this question, let's say that this global actor manages the user's state, and answers questions like "Is the user signed in?".
This change has been pretty smooth sailing so far, up until the point where I need to call my actor in a synchronous system method that expects a return value. These are pretty common in the App Delegate for example i.e. UIApplication
's application(_:open:options:)
or application(_:continue:restorationHandler:)
, both of which expect a Boolean return value.
In this example, I might need to first call something like await isUserSignedIn
in order to access my actor. This isUserSignedIn
method might not do any heavy lifting, and in fact, before it was an actor, it just ran on the main thread as normal. However, now that it is an actor, it must be called asynchronously.
Of course, those system callbacks are not async (understandably).
What is the best way to deal with this situation? It would be a shame if I had to explicitly block the main thread using something like a semaphore (even though that is essentially what isUserSignedIn
already did, before it was an actor).
Thoughts?