Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Actors in Go: How lockstep Runs One Actor in Your Program and in Tests

Description and use

The article demonstrates implementing an actor model in Go using lockstep: typed messages, bounded mailboxes, non-blocking effects, and deterministic testing.

Problem

Implementing actor semantics in Go without a dedicated runtime, managing state, bounded mailboxes, and non-blocking I/O.

Outcome

The shop actor correctly reserves stock before charging, uses lockstep.Do for non-blocking I/O, and runs deterministically in tests.

Workflow

  • Define message types and actor struct
  • Implement Receive to handle Buy, charged, and Sold messages
  • Use lockstep.Spawn to create actor and obtain typed PID
  • Send Buy messages to actor; lockstep.Do starts Charge effect
  • Handle charged result in a later turn
  • Reply with Sold message via ReplyTo
  • Run same code under go test with deterministic seed

Evidence

lockstep runs them in your program on a pool of worker goroutines.

Source

The same actor code also runs in go test, in a simulation with its own clock and network.

Source

lockstep.Do starts an effect and returns at once.

Source

  • Record date: 2026-11-02T18:14:12.456Z