10.4 · Actors, reentrancy, isolated, nonisolated, global actors and @MainActor

Actors make “who may touch this state” a property the compiler checks. The price is that every hop is an await, and every await is a chance for the world to change.

Mental model. An actor is a serial gatekeeper for its state. Inside, code runs one piece at a time; between two awaits, anything can happen.

Actors

Isolation, reentrancy and what an actor does not guarantee.

  1. What does an actor guarantee, and what is actor reentrancy? 10.4.1 · L5
    An actor is a reference type that protects its mutable state: only one piece of code runs on the actor at a time, and from outside you may touch its isolated…

Isolation domains

Global actors, <code>@MainActor</code>, <code>isolated</code> and <code>nonisolated</code>.

  1. How do @MainActor, global actors, isolated and nonisolated work, and how does isolation propagate? 10.4.2 · L5
    Every piece of code has an isolation domain: an actor instance, a global actor, or none (nonisolated). A global actor is a single, shared actor you attach with…

More in Concurrency