nqe-0.6.1: Concurrency library in the style of Erlang/OTP

CopyrightNo rights reserved
Safe HaskellNone



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.



type ChildAction = IO () Source #

Alias for child action to be executed asynchronously by supervisor.

type Child = Async () Source #

Thread handler for child.

data SupervisorMessage Source #

Send this message to a supervisor to add or remove a child.

type Supervisor = Process SupervisorMessage Source #

Alias for supervisor process.

data Strategy Source #

Supervisor strategies to decide what to do when a child stops.


Notify (Listen (Child, Maybe SomeException))

send a SupervisorNotif to Mailbox when child dies


kill all processes and propagate exception upstream


ignore processes that stop without raising an exception


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.