Gleam Actor Model
FreeNo executable scriptsNot checkedUse when oTP actor patterns in Gleam including processes, message passing, GenServer implementations, supervisors, fault tolerance, state management, and…
by TheBushidoCollective★ 202 GitHub starsAbout this skill
Gleam Actor Model
Introduction
Gleam leverages the Erlang VM's actor model, enabling lightweight concurrent processes that communicate through message passing. This model provides inherent fault tolerance, isolation, and scalability, making it ideal for building distributed systems.
The actor model in Gleam uses OTP (Open Telecom Platform) patterns including GenServers for stateful processes, supervisors for fault recovery, and message passing for inter-process communication. Each process has its own heap and communicates asynchronously, eliminating shared memory concerns.
This skill covers process creation and message passing, GenServer pattern for stateful actors, supervisors and fault tolerance, process linking and monitoring, selective receive, and patterns for building robust concurrent applications.
Process Basics and Message Passing
Processes are lightweight, isolated units of execution that communicate via message passing.
import gleam/erlang/process
import gleam/io
// Basic process creation
pub fn simple_process() {
process.spawn(fn() {
io.println("Hello from process!")
})
}
// Process with message passing
pub type Message {
Ping
Pong
Stop
}
pub fn echo_process() {
let subject = process.new_subject()
process.spawn(fn() {
loop(subject)
})
subject
}
fn loop(subject: process.Subject(Message)) {
case process.receive(subject, 1000) {
Ok(Ping) -> {
io.println("Received Ping")
loop(subject)
}
Ok(Pong) -> {
io.println("Received Pong")
loop(subject)
}
Ok(Stop) -> {
io.println("Stopping")
Nil
}
Error(_) -> {
io.println("Timeout")
loop(subject)
}
}
}
// Sending messages
pub fn send_messages(subject: process.Subject(Message)) {
process.send(subject, Ping)
process.send(subject, Pong)
process.send(subject, Stop)
}
// Request-response pattern
pub type Request {
GetValue(reply_to: process.Subject(Int))
SetValue(value: Int, reply_to: process.Subject(Nil))
}
pub fn state_process(initial: Int) {
let subject = process.new_subject()
process.spawn(fn() {
state_loop(subject, initial)
})
subject
}
fn state_loop(subject: process.Subject(Request), state: Int) {
case process.receive(subject, 5000) {
Ok(GetValue(reply_to)) -> {
process.send(reply_to, state)
state_loop(subject, state)
}
Ok(SetValue(value, reply_to)) -> {
process.send(reply_to, Nil)
state_loop(subject, value)
}
Error(_) -> state_loop(subject, state)
}
}
// Calling the state process
pub fn use_state_process() {
let proc = state_process(0)
let reply_subject = process.new_subject()
// Set value
process.send(proc, SetValue(42, reply_subject))
let _ack = process.receive(reply_subject, 1000)
// Get value
process.send(proc, GetValue(reply_subject))
case process.receive(reply_subject, 1000) {
Ok(value) -> io.debug(value)
Error(_) -> io.println("Timeout")
}
}
// Process with multiple message types
pub type ServerMessage {
Request(id: Int, reply_to: process.Subject(String))
Broadcast(message: String)
Shutdown
}
pub fn multi_message_process() {
let subject = process.new_subject()
process.spawn(fn() {
multi_loop(subject, [])
})
subject
}
fn multi_loop(
subject: process.Subject(ServerMessage),
clients: List(process.Subject(String)),
) {
case process.receive(subject, 1000) {
Ok(Request(id, reply_to)) -> {
let response = "Response for " <> int.to_string(id)
process.send(reply_to, response)
multi_loop(subject, [reply_to, ..clients])
}
Ok(Broadcast(message)) -> {
list.each(clients, fn(client) {
process.send(client, message)
})
multi_loop(subject, clients)
}
Ok(Shutdown) -> Nil
Error(_) -> multi_loop(subject, clients)
}
}
// Process pools
pub fn worker_pool(size: Int) -> List(process.Subject(Message)) {
list.range(1, size)
|> list.map(fn(_) { echo_process() })
}
pub fn distribute_work(pool: List(process.Subject(Message)),
work: List(Message)) {
list.zip(work, list.cycle(pool))
|> list.each(fn(pair) {
let #(message, worker) = pair
process.send(worker, message)
})
}
Lightweight processes with message passing enable concurrent applications without shared memory complexity.
GenServer Pattern
GenServer provides a standard pattern for stateful processes with synchronous and asynchronous operations.
import gleam/otp/actor
import gleam/erlang/process
// State type
pub type Counter {
Counter(value: Int)
}
// Message types
pub type CounterMessage {
Increment
Decrement
GetValue(reply_to: process.Subject(Int))
Reset(reply_to: process.Subject(Nil))
}
// GenServer implementation
pub fn start_counter() -> Result(process.Subject(CounterMessage),
actor.StartError) {
actor.start(Counter(value: 0), handle_message)
}
fn handle_message(
message: Coun
Install Gleam Actor Model in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the Gleam Actor Model skill do?
Use when oTP actor patterns in Gleam including processes, message passing, GenServer implementations, supervisors, fault tolerance, state management, and building concurrent, fault-tolerant applications on the Erlang VM.
How do I install the Gleam Actor Model skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the Gleam Actor Model skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
by Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
by Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropic