threads-supervisor-1.2.0.1: Simple, IO-based library for Erlang-style thread supervision

Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Supervisor

Synopsis

Documentation

data RestartStrategy Source #

Erlang inspired strategies. At the moment only the OneForOne is implemented.

Constructors

OneForOne 

data Child_ q Source #

data RestartResult Source #

Constructors

Restarted !ThreadId !ThreadId !RetryStatus !UTCTime

The supervised Child_ was restarted successfully.

StaleDeadLetter !ThreadId !LetterEpoch !ChildEpoch !UTCTime

A stale DeadLetter was received.

RestartFailed SupervisionEvent

The restart failed for a reason decribed by a SupervisionEvent

class QueueLike q where Source #

Methods

newQueueIO :: Natural -> IO (q a) Source #

readQueue :: q a -> STM a Source #

writeQueue :: q a -> a -> STM () Source #

fibonacciRetryPolicy :: RetryPolicyM IO Source #

Smart constructor which offers a default throttling based on fibonacci numbers.

eventStream :: QueueLike q => Supervisor q -> q SupervisionEvent Source #

Gives you access to the event this supervisor is generating, allowing you to react. It's using a bounded queue to explicitly avoid memory leaks in case you do not want to drain the queue to listen to incoming events.

activeChildren :: QueueLike q => Supervisor q -> IO Int Source #

Returns the number of active threads at a given moment in time.

shutdownSupervisor :: QueueLike q => Supervisor q -> IO () Source #

Shutdown the given supervisor. This will cause the supervised children to be killed as well. To do so, we explore the children tree, killing workers as we go, and recursively calling shutdownSupervisor in case we hit a monitored Supervisor.

forkSupervised Source #

Arguments

:: QueueLike q 
=> Supervisor q

The Supervisor

-> RetryPolicyM IO

The retry policy to use

-> IO ()

The computation to run

-> IO ThreadId 

Fork a thread in a supervised mode.

monitorWith Source #

Arguments

:: QueueLike q 
=> RetryPolicyM IO

The retry policy to use

-> Supervisor q

The supervisor

-> Supervisor q

The supervised supervisor

-> IO ThreadId 

Monitor another supervisor. To achieve these, we simulate a new DeadLetter, so that the first supervisor will effectively restart the monitored one. Thanks to the fact that for the supervisor the restart means we just copy over its internal state, it should be perfectly fine to do so. Returns the ThreadId of the monitored supervisor.