Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Actors

Actors are Acton's primary unit for state and concurrency.

If you are looking for the Acton answer to Rust-style lifetime concerns, this is it: actors own mutable state, capabilities are passed explicitly, and the runtime handles ordinary object lifetime.

If classes feel like objects that own data, actors are a useful way to think about objects that own state and participate in concurrent work. The actor body runs once when the actor starts; its methods run later in response to calls.

An actor combines:

  • private state owned by one actor
  • sequential execution inside that actor
  • method-based communication with other actors
  • a place to put mutable program state
actor Greeter(name):
    print("starting", name)

    def hello():
        print("hello from", name)

actor main(env):
    greeter = Greeter("Acton")
    await async greeter.hello()

    env.exit(0)

Code in the actor body runs once when the actor is created. That body is where initialization happens, and it may define methods that operate on the actor's private state.

Actors are also where several Acton-specific language pieces meet: var, await, async, after, capability passing, and effectful APIs. The main guarantee is actor-local sequentiality: state changes happen one handled message at a time inside that actor.