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

Safe HaskellNone




data RestartStrategy Source #

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



data Child_ q Source #

data RestartResult Source #


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 #


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 #


:: 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 #


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