supervisors- Monitor groups of threads with non-hierarchical lifetimes.

Safe HaskellSafe



This module exposes a Supervisor construct, which can be used to safely spawn threads while guaranteeing that:

  • When the supervisor is killed, all of the threads it supervises will be killed.
  • Child threads can terminate in any order, and memory usage will always be proportional to the number of *live* supervised threads.


data Supervisor Source #

A handle for a supervisor, which montiors a pool of threads.

withSupervisor :: (Supervisor -> IO a) -> IO a Source #

Run an IO action with access to a supervisor. Threads spawned using the supervisor will be killed when the action returns.

supervise :: Supervisor -> IO () -> IO () Source #

Launch the IO action in a thread, monitored by the Supervisor. If the supervisor receives an exception, the exception will also be raised in the child thread.

superviseSTM :: Supervisor -> IO () -> STM () Source #

Like supervise, but can be used from inside STM. The thread will be spawned if and only if the transaction commits.