Actor Isolation and nonisolated
Reason about isolation boundaries.
What Is Actor Isolation?
Actor isolation means an actor’s mutable state can only be touched by code running on that actor.
The runtime serializes access so two tasks never mutate the state simultaneously, eliminating data races.
actor Counter {
private var value = 0
func increment() { value += 1 }
}Calling Into an Actor
From outside the actor, accessing isolated members is asynchronous. You must await because the call may suspend until the actor is free.
let counter = Counter()
func useCounter() async {
await counter.increment()
}All lessons in this course
- The Data Race Problem
- The Sendable Protocol
- Actor Isolation and nonisolated
- Migrating to Strict Concurrency