Stateless Actors
May 29, 2026
Recently, I was asked an interesting question. If the purpose of an actor is to protect mutable state, is a stateless actor pointless?
At first, I thought it was an easy answer. Actors exist to define a little, protective bubble around state. They "isolate" data away from any unsafe accesses. An actor that has nothing to isolate seems like a strange thing.
Can such an arrangement serve a purpose?
Note I wrote another thing on actors that might be interesting.
Easy non-MainActor types
A thing I run into from time to time is a "NetworkClient"-style type. It contains methods that deal with some network API. It isn't uncommon for these kinds of types to be actors.
actor NetworkClient { func loadCart ( ) async throws -> [Product] { let (data, _) = try await URLSession . shared . data( for : cartRequest) return try JSONDecoder() . decode([Product] . self , from: data) } }
This particular NetworkClient is an actor that has no state. But it being an actor gives it two advantages. First, actor types are Sendable . That means we can pass this type around easily without having to think very much.
... continue reading