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

Safe HaskellNone
LanguageHaskell2010

Supervisors

Description

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.
Synopsis

Documentation

data Supervisor Source #

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

withSupervisor :: (Supervisor -> IO ()) -> IO () 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.