-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Description
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 = mxReadyOn 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.