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

Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Supervisor.Types

Contents

Synopsis

Documentation

class QueueLike q where Source #

Methods

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

readQueue :: q a -> STM a Source #

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

data Child_ q Source #

data RestartStrategy Source #

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

Constructors

OneForOne 

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

Creating a new supervisor

In order to create a new supervisor, you need a SupervisorSpec, which can be acquired by a call to newSupervisor:

Restart Policies

fibonacciRetryPolicy :: RetryPolicyM IO Source #

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

Stopping a supervisor

 

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.

Accessing Supervisor event log

 

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.

Supervise a forked thread

 

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.

Monitor another supervisor

 

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.