Doing work without blocking.
WHY IT MATTERS
Blocking the main thread freezes the interface, and the system terminates unresponsive applications.
WHAT MUST HAPPEN ON THE MAIN THREAD
All interface updates, without exception.
WHAT THAT MEANS
Work performed elsewhere must return to the main thread before touching the interface.
WHAT HAPPENS OTHERWISE
Unpredictable behaviour and crashes, frequently intermittent.
WHAT THE MODERN APPROACH PROVIDES
Asynchronous code written sequentially, with the compiler enforcing where work runs.
WHAT ACTORS PROVIDE
Protected state that only one task accesses at a time.
WHY THAT MATTERS
It prevents data races, which are otherwise intermittent and extremely difficult to diagnose.
WHAT THE MAIN ACTOR DESIGNATES
Code that must run on the main thread.
WHAT TO MARK WITH IT
View models and anything touching the interface.
WHAT TO AVOID
Blocking calls on the main thread Unstructured background work with no cancellation Shared mutable state accessed from several tasks
WHAT TO ALWAYS SUPPORT
Cancellation, so work stops when a screen is dismissed.
WHAT TO TEST
Rapid navigation, which exposes work continuing after dismissal.