Actors and Subjects (2/3)

Mar 22, 2026   Kero van Gelder
In this series we are going to look at managing concurrency in Gleam in the following ways:
  1. plain processes
  2. actors and subjects (this post)
  3. supervised actors (not yet published)
This series supersedes an earlier series of 3 posts that I made in 2024 on this same blog.

Actors

A gleam actor has no equivalent in Erlang. It is a process that receives statically typed messages. In erlang, a gen_server receives dynamically typed messages.

Subjects

Subjects are the statically typed channels over which the messages are sent to an actor. Responses return via their own subjects (they have to, responses to different messages may have different types).

A simple actor

An actor with a separate initialization

The subject is passed in and can be returned to the caller

An actor with a named subject

The subject isn't passed around, the name is. This name is still statically typed.