Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class Actor a where
- data Responder a
- data Responded
- respond :: MonadIO m => Responder a -> a -> m Responded
- call :: (Actor actor, MonadIO m) => actor -> (Responder a -> Msg actor) -> m a
- cast :: (Actor actor, MonadIO m) => actor -> Msg actor -> m ()
- logUnexpectedTermination :: (MonadLogger m, MonadCatch m) => ProcessName -> m a -> m a
- newtype ProcessName = ProcessName {}
- type Race = ?scope :: Scope
- runRace :: MonadUnliftIO m => (Race => m a) -> m a
- race :: (MonadCatch m, MonadLogger m, MonadUnliftIO m, Race) => ProcessName -> m a -> m ()
- wait :: (MonadIO m, Race) => m ()
Actor Communication.
The class of types that can act as the handle for an asynchronous actor.
How to respond to a asynchronous message.
:: (Actor actor, MonadIO m) | |
=> actor | The actor to which we are sending a call request. |
-> (Responder a -> Msg actor) | Given a way for the actor to respond to the message, construct a message that should be sent to the actor. Typically, your data MyMsg = MsgWithResponse SomeData (Responder ResponseType) -- In this example, this type of message requires a -- response. We package the responder up as part of the -- message itself. Idiomatically it is best to put the -- responder as the last argument so that it is easy to pass -- 'MsgWithResponse someData' to 'call'. | MsgWithoutResponse SomeData -- In this example, this type of message requires no response. It -- is a "fire and forget" message. you will call do response <- call actor (MsgWithResponse someData) -- response :: ResponseType |
-> m a |
Send a message to an actor, and wait for a response.
cast :: (Actor actor, MonadIO m) => actor -> Msg actor -> m () Source #
Send a message to an actor, but do not wait for a response.
Forking Background Processes.
logUnexpectedTermination :: (MonadLogger m, MonadCatch m) => ProcessName -> m a -> m a Source #
Log (at WARN) when the action terminates for any reason.
newtype ProcessName Source #
The name of a process.
Instances
IsString ProcessName Source # | |
Defined in OM.Fork fromString :: String -> ProcessName # | |
Monoid ProcessName Source # | |
Defined in OM.Fork mempty :: ProcessName # mappend :: ProcessName -> ProcessName -> ProcessName # mconcat :: [ProcessName] -> ProcessName # | |
Semigroup ProcessName Source # | |
Defined in OM.Fork (<>) :: ProcessName -> ProcessName -> ProcessName # sconcat :: NonEmpty ProcessName -> ProcessName # stimes :: Integral b => b -> ProcessName -> ProcessName # | |
Show ProcessName Source # | |
Defined in OM.Fork showsPrec :: Int -> ProcessName -> ShowS # show :: ProcessName -> String # showList :: [ProcessName] -> ShowS # |
type Race = ?scope :: Scope Source #
This constraint indicates that we are in the context of a thread race. If any
threads in the race terminate, then all threads in the race terminate.
Threads are "in the race" if they were forked using race
.
:: MonadUnliftIO m | |
=> (Race => m a) |
|
-> m a |
Run a thread race.
Within the provided action, you can call race
to fork new background
threads. When the action terminates, all background threads forked
with race
are also terminated. Likewise, if any one of the racing
threads terminates, then all other racing threads are terminated _and_
runRace
will throw an exception.
In any event, when runRace
returns, all background threads forked
by the action
using race
will have been terminated.
race :: (MonadCatch m, MonadLogger m, MonadUnliftIO m, Race) => ProcessName -> m a -> m () Source #
Fork a new thread within the context of a race. This thread will be terminated when any other racing thread terminates, or else if this thread terminates first it will cause all other racing threads to be terminated.
Generally, we normally expect that the thread is a "background thread" and will never terminate under "normal" conditions.