Actor Types #
A handle to send messages to an actor. Can be freely cloned and shared across threads.
- mailbox : Channel.Unbounded Msg
Instances For
def
Lapis.Concurrent.Actor.ActorRef.call
{Resp Msg : Type}
[Nonempty Resp]
(ref : ActorRef Msg)
(mkMsg : Channel.Oneshot Resp → Msg)
:
IO Resp
Send a message and get a response via oneshot channel
Equations
- ref.call mkMsg = do let reply ← Lapis.Concurrent.Channel.Oneshot.new ref.send (mkMsg reply) reply.recv
Instances For
Equations
- Lapis.Concurrent.Actor.instBEqActorStatus.beq x✝ y✝ = (x✝.ctorIdx == y✝.ctorIdx)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Configuration for actor behavior
Instances For
A running actor instance
- ref : ActorRef Msg
Reference to send messages
The running task
- status : IO.Ref ActorStatus
Actor status
- config : ActorConfig
Configuration
Instances For
Check if the actor is still running
Equations
- actor.isRunning = do let status ← ST.Ref.get actor.status pure (status == Lapis.Concurrent.Actor.ActorStatus.running)
Instances For
Request the actor to stop (gracefully)
Equations
- actor.stop = ST.Ref.set actor.status Lapis.Concurrent.Actor.ActorStatus.stopping
Instances For
Actor Spawning #
Message handler result
- continue
{State : Type}
(state : State)
: HandleResult State
Continue with new state
- stop
{State : Type}
: HandleResult State
Stop the actor
- error
{State : Type}
(msg : String)
: HandleResult State
Stop with error
Instances For
def
Lapis.Concurrent.Actor.spawn
{State Msg : Type}
(initialState : State)
(handler : State → Msg → IO (HandleResult State))
(config : ActorConfig := { })
:
Spawn a new actor with the given initial state and message handler. The handler is called sequentially for each message.
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Lapis.Concurrent.Actor.spawnWithErrorHandler
{State Msg : Type}
(initialState : State)
(handler : State → Msg → IO (HandleResult State))
(onError : String → IO Unit)
(config : ActorConfig := { })
:
Spawn an actor that can handle IO errors gracefully
Equations
- One or more equations did not get rendered due to their size.
Instances For
Typed Request-Response Pattern #
def
Lapis.Concurrent.Actor.Request.new
{Resp Req : Type}
[Nonempty Resp]
(payload : Req)
:
IO (Request Req Resp × Channel.Oneshot Resp)
Create a request and get the response channel
Equations
- Lapis.Concurrent.Actor.Request.new payload = do let reply ← Lapis.Concurrent.Channel.Oneshot.new pure ({ payload := payload, replyTo := reply }, reply)
Instances For
Actor Supervision #
Create a new supervisor
Equations
Instances For
Shutdown all supervised actors
Equations
- One or more equations did not get rendered due to their size.
Instances For
Utility Functions #
def
Lapis.Concurrent.Actor.refFromMailbox
{Msg : Type}
(mailbox : Channel.Unbounded Msg)
:
ActorRef Msg
Create an actor ref from an existing mailbox
Equations
- Lapis.Concurrent.Actor.refFromMailbox mailbox = { mailbox := mailbox }