Copyright | © 2022 Evan Relf |
---|---|
License | BSD-3-Clause |
Maintainer | evan@evanrelf.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Drama.Internal
Description
Synopsis
- newtype Actor (msg :: Type -> Type) a = Actor (ReaderT (ActorEnv msg) IO a)
- data ActorEnv msg = ActorEnv {}
- newtype Address msg = Address (InChan (Envelope msg))
- newtype Mailbox msg = Mailbox (OutChan (Envelope msg))
- data Envelope (msg :: Type -> Type) where
- data NoMsg res
- type Actor_ = Actor NoMsg
- spawn :: Actor msg () -> Actor _msg (Address msg)
- spawn_ :: Actor_ () -> Actor msg ()
- wait :: Actor msg ()
- getSelf :: Actor msg (Address msg)
- cast :: Address msg -> msg () -> Actor _msg ()
- call :: Address msg -> msg res -> Actor _msg res
- receive :: (forall res. msg res -> Actor msg res) -> Actor msg ()
- tryReceive :: (forall res. msg res -> Actor msg res) -> Actor msg Bool
- runActor :: MonadIO m => Actor msg a -> m a
- runActor_ :: MonadIO m => Actor_ a -> m a
Documentation
newtype Actor (msg :: Type -> Type) a Source #
Monad supporting actor operations.
Since: 0.4.0.0
Instances
Monad (Actor msg) Source # | |
Functor (Actor msg) Source # | |
MonadFix (Actor msg) Source # | |
Defined in Drama.Internal | |
MonadFail (Actor msg) Source # | |
Defined in Drama.Internal | |
Applicative (Actor msg) Source # | |
MonadIO (Actor msg) Source # | |
Defined in Drama.Internal | |
Alternative (Actor msg) Source # | |
MonadPlus (Actor msg) Source # | |
MonadUnliftIO (Actor msg) Source # | Since: 0.5.0.0 |
Defined in Drama.Internal |
Mailbox where an actor receives messages. Cannot be shared with other
actors; used implicitly by receive
and tryReceive
.
Since: 0.4.0.0
data Envelope (msg :: Type -> Type) where Source #
Wrapper around higher-kinded message types.
Higher-kinded message types are defined as GADTs with a type parameter. This allows specifying the response type for messages.
Since: 0.4.0.0
Spawn a child actor and return its address.
Since: 0.4.0.0
Send a message to another actor, expecting no response. Returns immediately without blocking.
Since: 0.4.0.0
Send a message to another actor, and wait for a response.
Since: 0.4.0.0
Arguments
:: (forall res. msg res -> Actor msg res) | Callback function that responds to messages |
-> Actor msg () |
Receive a message. When the mailbox is empty, blocks until a message arrives.
Since: 0.4.0.0
Arguments
:: (forall res. msg res -> Actor msg res) | Callback function that responds to messages |
-> Actor msg Bool |
Try to receive a message. When the mailbox is empty, returns immediately.
Since: 0.4.0.0
runActor :: MonadIO m => Actor msg a -> m a Source #
Run a top-level actor. Intended to be used at the entry point of your program.
If your program is designed with actors in mind, you can use Actor
as
your program's base monad:
main :: IO () main = runActor root root :: Actor RootMsg () root = do ...
Otherwise, use runActor
like you would with run
functions from libraries
like transformers
or mtl
.
Since: 0.4.0.0