Actor
Processes
Build and start a process that handles one message at a time.
Pipe new → onMessage → optional named → start. The handler returns continue nextState or stop. Most apps use higher-level wrappers ([Database.Repo], [Platform], [Jobs] supervised helpers) instead of calling `Actor` directly; reach for this when you need a custom long-lived process.
type Msg
= Incr
| Get (Process.Subject Int)
name : Process.Name Msg
name =
Process.newName "counter"
handle : Int -> Msg -> Actor.Next Int Msg
handle n msg =
case msg of
Incr ->
Actor.continue (n + 1)
Get reply ->
-- send the reply, then keep the same count
Actor.continue n
Actor.new 0
|> Actor.onMessage handle
|> Actor.named name
|> Actor.startReturn continue or stop from every branch. See [Process] for subjects and names. For TEA-shaped background work, prefer [Platform] `worker` and `supervised`.
Types
Builder
type Builder state message a = BuilderAn actor that is still being configured.
Examples
Actor.new initialState : Builder state message (Subject message)Next
type Next state message = NextWhat an actor does after handling one message.
Examples
Actor.continue (n + 1)Started
type Started a = Started Pid aA process that started and produced a (usually a Subject).
Examples
Ok (Actor.Started pid subject)StartError
type StartError
= InitTimeout
| InitFailed StringWhy starting a process failed.
Examples
Err Actor.InitTimeoutValues
new
new : state -> Builder state message (Subject message)Start an actor builder from its initial state.
Examples
Actor.new 0onMessage
onMessage : (state -> message -> Next state message) -> Builder state message a -> Builder state message aHandle each message with the current state. Return continue or stop.
Examples
Actor.onMessage handle buildernamed
named : Name message -> Builder state message a -> Builder state message aRegister the actor under a process name so others can look it up.
Examples
Actor.named name builderstart
start : Builder state message a -> Result StartError (Started a)Start the actor and return its pid plus the builder's result (often a Subject).
Examples
Actor.start buildercontinue
continue : state -> Next state messageKeep the actor running with the next state.
Examples
Actor.continue nextStatestop
stop : Next state messageStop the actor after this message.
Examples
Actor.stop