Skip to content

Provide MxAgents with a dual state model #307

@hyperthunk

Description

@hyperthunk

It's often the case that whilst initialising an agent might need to wait on other actors, so we should either copy the init >>= serve model from client-server, or provide a dual state monadic environment so we don't have code like this...

data AgentState = Booting | ActualState { f1 = ..., f2 = ... }

-- and inside a listener
startIt = mxAgent agentId Booting [ mxSink handlePeersReady, mxSink handleEvent ]
where
  handleEvent Booting = mxSkip 
  handleEvent ActualState{...} = ...

And worse still, have to worry about the boot state when you're buried in implementation code...

forwardToServer _   HBAgentBoot = liftMX terminate  -- state invariant
forwardToServer ev' HBAgent{ hbServer = sPid }
                                = liftMX (send sPid ev') >> mxReady

handleRestarts _   HBAgentBoot = liftMX terminate   -- state invariant
handleRestarts pid sta@HBAgent{ hbServer = sPid' }
        | pid == sPid' = restartBoth sta
        | otherwise    = mxReady

On the other hand, we want this API to remain as simple as possible, since here we're providing service and utility, and policy belongs elsewhere.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions