distributed-process icon indicating copy to clipboard operation
distributed-process copied to clipboard

Provide MxAgents with a dual state model

Open hyperthunk opened this issue 8 years ago • 0 comments

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.

hyperthunk avatar Feb 13 '17 01:02 hyperthunk