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

Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.Supervisor.Types

Contents

Synopsis

Documentation

type SupervisorSpec0 q = Supervisor_ q Uninitialised Source

type Supervisor0 q = Supervisor_ q Initialised Source

data Child_ q Source

data RestartStrategy Source

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

Constructors

OneForOne !Int RetryPolicy 

Creating a new supervisor spec

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

newSupervisorSpec :: QueueLike q => Int -> IO (SupervisorSpec0 q) Source

Creates a new SupervisorSpec. The reason it doesn't return a Supervisor is to force you to call supervise explicitly, in order to start the supervisor thread.

Creating a new supervisor

Restart Strategies

oneForOne :: RestartStrategy Source

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

Stopping a supervisor

 

shutdownSupervisor :: QueueLike q => Supervisor0 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 => Supervisor0 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 => Supervisor0 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 
=> Supervisor0 q

The Supervisor

-> RestartStrategy

The RestartStrategy to use

-> IO ()

The computation to run

-> IO ThreadId 

Fork a thread in a supervised mode.

Monitor another supervisor

 

monitor :: QueueLike q => Supervisor0 q -> Supervisor0 q -> IO () Source

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.