Actors

Actors
Login

Actors

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:

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.