import std/actor.{Continue, Stop} import std/io import std/process.{type Subject, type proc} type Counter { Add(Int), Get(Subject), Shutdown(Subject) } fn counter_step :: total: Int message: Counter -> actor.Next / { match message { Add(n) -> Continue(total + n) , Get(reply) -> { process.send reply total Continue(total) } , Shutdown(reply) -> { process.send reply ("stopped at " <> show total) Stop } } } pub fn main :: -> () / { // A lambda: the step function declares only the effects it uses, and // actors also get `clock` and `random` (ADR 0036). let counter = actor.start 0 fn total message { counter_step total message } actor.cast counter Add(5) actor.cast counter Add(37) io.println ("total " <> show (actor.call counter Get 100)) io.println (show (actor.try_call counter Get 100)) io.println (actor.call counter Shutdown 100) // Stopped: nobody answers. io.println (show (actor.try_call counter Get 100)) } //> total 42 //> Ok(42) //> stopped at 42 //> Error(Timeout)