feat: add pass, continue util functions

This commit is contained in:
2026-06-16 14:13:43 +02:00
parent 5ad62d5c75
commit 51cb3a95f5
+12 -9
View File
@@ -5,6 +5,8 @@ module Control.Actor
, module Control.Actor.Core , module Control.Actor.Core
, module Control.Actor.Supervision , module Control.Actor.Supervision
, module Control.Actor.Network , module Control.Actor.Network
, pass
, continue
-- Demo -- Demo
, pingActor , pingActor
, forwardActorWithCell , forwardActorWithCell
@@ -25,9 +27,16 @@ import Control.Concurrent.STM
( TMVar, TVar ( TMVar, TVar
, atomically, newEmptyTMVarIO, newTVarIO, readTMVar, readTVarIO, writeTQueue, writeTVar , atomically, newEmptyTMVarIO, newTVarIO, readTMVar, readTVarIO, writeTQueue, writeTVar
) )
import Control.Monad ((<=<))
import Control.Monad.Reader (MonadIO (..)) import Control.Monad.Reader (MonadIO (..))
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
continue :: r -> Actor u r
continue x = (,) (Just x) <$> state
pass :: Actor u r
pass = (,) Nothing <$> state
-- Demo -- Demo
pingActor :: String -> Actor () String pingActor :: String -> Actor () String
@@ -72,18 +81,12 @@ system = do
-- Network demo -- Network demo
replyWith :: r -> Actor u r newNodeActor :: NodeAddr -> Actor () NodeId
replyWith x = do newNodeActor = continue <=< liftRuntime . connect Nothing
s <- state
return (Just x, s)
pass :: Actor u r
pass = state >>= (return . (,) Nothing)
-- | Actor on node 2: echo — returns whatever it received. -- | Actor on node 2: echo — returns whatever it received.
echoActor :: String -> Actor () String echoActor :: String -> Actor () String
echoActor = replyWith echoActor = continue
-- | Actor on node 2: printer — side-effects only. -- | Actor on node 2: printer — side-effects only.
printerActor :: String -> Actor () () printerActor :: String -> Actor () ()