Copyright | No rights reserved |
---|---|
License | UNLICENSE |
Maintainer | xenog@protonmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Supervisors run and monitor processes, including other supervisors. A supervisor
has a corresponding Strategy
that controls its behaviour if a child stops.
Supervisors deal with exceptions in concurrent processes so that their code does
not need to be written in an overly-defensive style. They help prevent problems
caused by processes dying quietly in the background, potentially locking an
entire application.
Synopsis
- type ChildAction = IO ()
- type Child = Async ()
- data SupervisorMessage
- type Supervisor = Process SupervisorMessage
- data Strategy
- = Notify (Listen (Child, Maybe SomeException))
- | KillAll
- | IgnoreGraceful
- | IgnoreAll
- withSupervisor :: MonadUnliftIO m => Strategy -> (Supervisor -> m a) -> m a
- supervisor :: MonadUnliftIO m => Strategy -> m Supervisor
- supervisorProcess :: MonadUnliftIO m => Strategy -> Inbox SupervisorMessage -> m ()
- addChild :: MonadIO m => Supervisor -> ChildAction -> m Child
- removeChild :: MonadIO m => Supervisor -> Child -> m ()
Documentation
type ChildAction = IO () Source #
Alias for child action to be executed asynchronously by supervisor.
data SupervisorMessage Source #
Send this message to a supervisor to add or remove a child.
type Supervisor = Process SupervisorMessage Source #
Alias for supervisor process.
Supervisor strategies to decide what to do when a child stops.
Notify (Listen (Child, Maybe SomeException)) | send a |
KillAll | kill all processes and propagate exception upstream |
IgnoreGraceful | ignore processes that stop without raising an exception |
IgnoreAll | keep running if a child dies and ignore it |
withSupervisor :: MonadUnliftIO m => Strategy -> (Supervisor -> m a) -> m a Source #
Run a supervisor asynchronously and pass its mailbox to a function. Supervisor will be stopped along with all its children when the function ends.
supervisor :: MonadUnliftIO m => Strategy -> m Supervisor Source #
Run a supervisor as an asynchronous process.
supervisorProcess :: MonadUnliftIO m => Strategy -> Inbox SupervisorMessage -> m () Source #
Run a supervisor in the current thread.
addChild :: MonadIO m => Supervisor -> ChildAction -> m Child Source #
Add a new ChildAction
to the supervisor. Will return the Child
that was
just started. This function will not block or raise an exception if the child
dies.
removeChild :: MonadIO m => Supervisor -> Child -> m () Source #
Stop a Child
controlled by this supervisor. Will block until the child
dies.