Std.Actor
Concurrency primitives for the BEAM actor model. Provides process spawning, message passing, monitoring, linking, and timers.
Types
Pid
type Pid msg =
| Pid Int
deriving (Eq, Debug)Process identifier, parameterized by the message type the process accepts. At runtime this is an Erlang pid. The constructor is exposed so handler authors can build alternative implementations (e.g. sync handlers for testing).
ExitReason
type ExitReason =
| Normal
| Shutdown
| Killed
| Noproc
| Error String
| Other StringExit reasons for monitored processes
SystemMsg
type SystemMsg =
| Down (Pid a) ExitReason
| Exit (Pid a) ExitReasonSystem messages delivered to the mailbox by the runtime (e.g. monitor notifications). These can be matched in receive blocks alongside regular messages.
MonitorRef
opaque type MonitorRefTimerRef
opaque type TimerRefTimer effect: delays and scheduled messages
Effects
Process
effect Process {
fun spawn : (f: Unit -> Unit needs {Actor msg, ..e}) -> Pid msg needs {Actor msg, ..e}
fun send : (pid: Pid msg) -> (msg: msg) -> Unit
fun exit : (pid: Pid msg) -> ExitReason -> Unit
}Type variable msg is free per call site, inferred from the pid / spawned function.
Actor
effect Actor msg {
fun self : Unit -> Pid msg
}Actor effect: parameterized by the current process's message type. Only self and receive use this (scoped to this process's mailbox).
Monitor
effect Monitor {
fun monitor : (pid: Pid msg) -> MonitorRef
fun demonitor : (ref: MonitorRef) -> Unit
}Monitor processes and get notified when they die
Link
effect Link {
fun link : (pid: Pid msg) -> Unit
fun unlink : (pid: Pid msg) -> Unit
}Bidirectional crash propagation between processes
Timer
effect Timer {
fun sleep : (ms: Int) -> Unit
fun send_after : (pid: Pid msg) -> (ms: Int) -> (msg: msg) -> TimerRef
fun cancel_timer : (ref: TimerRef) -> Unit
}Handlers
beam_actor
handler beam_actor for Process, Actor msg, Monitor, Link, TimerNative handler for BEAM effects