Actors for Go. An actor is a little server, run on a go-routine of its own: it is spawned, it owns its state, it receives messages from its mailbox one at a time, and eventually it terminates.
The package documentation is the reference, and carries complete runnable examples — a plain adder, a running total under back pressure, and an adder supervised by a manager. There is also an introduction and tutorial.
Motivation
Go-routines and channels are fine raw material, but they compose more readily into pipelines than into services. A stateful service needs request-and-reply, many clients sharing one resource safely, orderly shutdown, and a way to learn that something elsewhere has died; with bare channels, each of those is machinery you build yourself, again, for every project. This library is that machinery built once, in a shape borrowed from Erlang:
State belongs to one go-routine. Only the actor's own go-routine touches its server's fields, so there is no locking and there are no data races: within a server you reason single-threadedly, whilst any number of go-routines send to it concurrently.
Termination is part of the model. An actor terminates by returning an error, and a panic is caught, attributed to the actor's own stack, and reported the same way rather than killing the process. Termination can be waited upon and subscribed to; clients of a terminated actor are released and told, never left blocked.
Supervision. A manager ties its children's fates to its own: a child which fails terminates its manager, and a terminating manager first terminates its children, so an entire tree of actors can be stopped — and waited upon — as one. Supervision only ever stops actors; nothing is restarted.
Unbounded mailboxes, with back pressure to opt into. Sending never blocks on a full queue, so two actors sending to each other cannot deadlock there. Where a fast sender could instead outrun a slow actor, a throttled client paces it, and the mailbox's growth stays bounded after all.
Every actor is named. A child is named beneath its parent, and each actor's logger (zerolog) is tagged with its full path, so a log line from deep within a tree names the whole chain it hangs from.
What is in the box
The root package, wellquite.org/actors, is the library: a server is a struct embedding one of three bases — ServerBase, BackPressureServerBase, or ManagerServerBase — overriding only the methods it needs, and its client embeds a Client, adding a method per message. Synchronous messages, termination subscriptions, spawn-time hooks, and a finite state machine round it out.
wellquite.org/actors/mailbox is the unbounded queue which sits between an actor and its clients.
wellquite.org/actors/step takes message-interleaving away from the Go scheduler: children of a step manager receive one message at a time, the next receiver picked by a function you supply. Drive that from a seeded rand.Rand and a whole run repeats exactly; drive it from a fuzzer's bytes and the fuzzer hunts for the schedule which breaks you.