| Copyright | (c) Samuel Schlesinger 2020 |
|---|---|
| License | MIT |
| Maintainer | sgschlesinger@gmail.com |
| Stability | experimental |
| Portability | POSIX, Windows |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Control.Concurrent.Actor
Description
Synopsis
- data ActionT message m a
- data Actor message
- send :: Actor message -> message -> STM ()
- addAfterEffect :: Actor message -> (Maybe SomeException -> IO ()) -> STM ()
- threadId :: Actor message -> ThreadId
- livenessCheck :: Actor message -> STM Liveness
- withLivenessCheck :: (Actor message -> x -> STM ()) -> Actor message -> x -> STM ()
- data Liveness
- data ActorDead = ActorDead (Maybe SomeException)
- actFinally :: (Either SomeException a -> IO ()) -> ActionT message IO a -> IO (Actor message)
- act :: ActionT message IO a -> IO (Actor message)
- receiveSTM :: MonadIO m => (message -> STM a) -> ActionT message m a
- receive :: MonadIO m => (message -> ActionT message m a) -> ActionT message m a
- hoistActionT :: (forall x. m x -> n x) -> ActionT message m a -> ActionT message n a
- link :: MonadIO m => Actor message -> ActionT message' m ()
- linkSTM :: Actor message -> Actor message' -> STM ()
- data LinkKill = LinkKill ThreadId
- self :: Applicative m => ActionT message m (Actor message)
- murder :: MonadIO m => Actor message -> m ()
- data MurderKill = MurderKill ThreadId
Documentation
data ActionT message m a Source #
A type that contains the actions that Actors will do.
Instances
A handle to do things to actors, like sending them messages, fiddling with their threads, or adding an effect that will occur after they've finished executing.
addAfterEffect :: Actor message -> (Maybe SomeException -> IO ()) -> STM () Source #
withLivenessCheck :: (Actor message -> x -> STM ()) -> Actor message -> x -> STM () Source #
Allows us to wrap addAfterEffect, send, and any other custom
combinators in a liveness check. This causes contention on the
underlying TVar that contains the status report of the Actor, and
thus should be avoided where possible. That being said, it is also
useful to avoid sending messages or add after effects to dead actors,
which will certainly be lost forever. If the Actor is Completed or
ThrewException, then we throw an ActorDead exception with Nothing
or Just the exception, respectively.
The liveness state of a particular Actor.
Constructors
| Alive | |
| Completed | |
| ThrewException SomeException |
The exception thrown when we run an action wrapped in
withLivenessCheck on an Actor which has died.
Constructors
| ActorDead (Maybe SomeException) |
Instances
| Show ActorDead Source # | |
| Exception ActorDead Source # | |
Defined in Control.Concurrent.Actor Methods toException :: ActorDead -> SomeException # fromException :: SomeException -> Maybe ActorDead # displayException :: ActorDead -> String # | |
actFinally :: (Either SomeException a -> IO ()) -> ActionT message IO a -> IO (Actor message) Source #
Perform some ActionT in a thread, with some cleanup afterwards.
receiveSTM :: MonadIO m => (message -> STM a) -> ActionT message m a Source #
Receive a message and, in the same transaction, produce some result.
receive :: MonadIO m => (message -> ActionT message m a) -> ActionT message m a Source #
Receive a message and do some ActionT with it.
hoistActionT :: (forall x. m x -> n x) -> ActionT message m a -> ActionT message n a Source #
Use a natural transformation to transform an ActionT on one base
monad to another.
The exception thrown when an actor we've linked with has died.
Instances
| Show LinkKill Source # | |
| Exception LinkKill Source # | |
Defined in Control.Concurrent.Actor Methods toException :: LinkKill -> SomeException # fromException :: SomeException -> Maybe LinkKill # displayException :: LinkKill -> String # | |
self :: Applicative m => ActionT message m (Actor message) Source #
Returns the Actor handle of the actor executing this action.
murder :: MonadIO m => Actor message -> m () Source #
Throws a MurderKill exception to the given Actor.
data MurderKill Source #
Constructors
| MurderKill ThreadId |
Instances
| Show MurderKill Source # | |
Defined in Control.Concurrent.Actor Methods showsPrec :: Int -> MurderKill -> ShowS # show :: MurderKill -> String # showList :: [MurderKill] -> ShowS # | |
| Exception MurderKill Source # | |
Defined in Control.Concurrent.Actor Methods toException :: MurderKill -> SomeException # fromException :: SomeException -> Maybe MurderKill # displayException :: MurderKill -> String # | |