-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple, IO-based library for Erlang-style thread supervision -- -- Simple, IO-based library for Erlang-style thread supervision @package threads-supervisor @version 1.2.0.2 -- | Use threads-supervisor if you want the "poor-man's Erlang -- supervisors". threads-supervisor is an IO-based library with -- minimal dependencies which does only one thing: It provides you a -- Supervisor entity you can use to monitor your forked -- computations. If one of the managed threads dies, you can decide if -- and how to restart it. This gives you: -- -- -- -- You can install the threads-supervisor library by running: -- > $ cabal install threads-supervisor module Control.Concurrent.Supervisor.Tutorial module Control.Concurrent.Supervisor.Types data SupervisionCtx q data Supervisor q class QueueLike q newQueueIO :: QueueLike q => Natural -> IO (q a) readQueue :: QueueLike q => q a -> STM a writeQueue :: QueueLike q => q a -> a -> STM () data Child_ q data DeadLetter type RestartAction = ThreadId -> IO ThreadId data SupervisionEvent ChildBorn :: !ThreadId -> !UTCTime -> SupervisionEvent ChildDied :: !ThreadId -> !SomeException -> !UTCTime -> SupervisionEvent ChildRestarted :: !ThreadId -> !ThreadId -> !RetryStatus -> !UTCTime -> SupervisionEvent ChildNotFound :: !ThreadId -> !UTCTime -> SupervisionEvent StaleDeadLetterReceived :: !ThreadId -> !LetterEpoch -> !ChildEpoch -> !UTCTime -> SupervisionEvent ChildRestartLimitReached :: !ThreadId -> !RetryStatus -> !UTCTime -> SupervisionEvent ChildFinished :: !ThreadId -> !UTCTime -> SupervisionEvent -- | Erlang inspired strategies. At the moment only the OneForOne is -- implemented. data RestartStrategy OneForOne :: RestartStrategy data RestartResult -- | The supervised Child_ was restarted successfully. Restarted :: !ThreadId -> !ThreadId -> !RetryStatus -> !UTCTime -> RestartResult -- | A stale DeadLetter was received. StaleDeadLetter :: !ThreadId -> !LetterEpoch -> !ChildEpoch -> !UTCTime -> RestartResult -- | The restart failed for a reason decribed by a SupervisionEvent RestartFailed :: SupervisionEvent -> RestartResult newSupervisor :: QueueLike q => RestartStrategy -> Natural -> IO (Supervisor q) -- | Smart constructor which offers a default throttling based on fibonacci -- numbers. fibonacciRetryPolicy :: RetryPolicyM IO -- | 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. shutdownSupervisor :: QueueLike q => Supervisor q -> IO () -- | 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. eventStream :: QueueLike q => Supervisor q -> q SupervisionEvent -- | Returns the number of active threads at a given moment in time. activeChildren :: QueueLike q => Supervisor q -> IO Int -- | Fork a thread in a supervised mode. forkSupervised :: QueueLike q => Supervisor q -> RetryPolicyM IO -> IO () -> 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. monitorWith :: QueueLike q => RetryPolicyM IO -> Supervisor q -> Supervisor q -> IO ThreadId instance GHC.Show.Show Control.Concurrent.Supervisor.Types.LetterEpoch instance GHC.Show.Show Control.Concurrent.Supervisor.Types.ChildEpoch instance GHC.Show.Show Control.Concurrent.Supervisor.Types.SupervisionEvent instance GHC.Show.Show Control.Concurrent.Supervisor.Types.RestartResult instance GHC.Show.Show Control.Concurrent.Supervisor.Types.RestartStrategy instance Control.Concurrent.Supervisor.Types.QueueLike Control.Concurrent.STM.TQueue.TQueue instance Control.Concurrent.Supervisor.Types.QueueLike Control.Concurrent.STM.TBQueue.TBQueue -- | This module offers a Bounded supervisor variant, where -- SupervisionEvent(s) are written on a TBQueue, and simply -- discarded if the queue is full. module Control.Concurrent.Supervisor.Bounded type Supervisor = Supervisor TBQueue type Child = Child_ TBQueue newSupervisor :: RestartStrategy -> Natural -> IO Supervisor -- | The default size of the queue where SupervisionEvent(s) are -- written. defaultEventQueueSize :: Natural -- | Erlang inspired strategies. At the moment only the OneForOne is -- implemented. data RestartStrategy OneForOne :: RestartStrategy data SupervisionEvent ChildBorn :: !ThreadId -> !UTCTime -> SupervisionEvent ChildDied :: !ThreadId -> !SomeException -> !UTCTime -> SupervisionEvent ChildRestarted :: !ThreadId -> !ThreadId -> !RetryStatus -> !UTCTime -> SupervisionEvent ChildNotFound :: !ThreadId -> !UTCTime -> SupervisionEvent StaleDeadLetterReceived :: !ThreadId -> !LetterEpoch -> !ChildEpoch -> !UTCTime -> SupervisionEvent ChildRestartLimitReached :: !ThreadId -> !RetryStatus -> !UTCTime -> SupervisionEvent ChildFinished :: !ThreadId -> !UTCTime -> SupervisionEvent type RestartAction = ThreadId -> IO ThreadId data Child_ q data RestartResult -- | The supervised Child_ was restarted successfully. Restarted :: !ThreadId -> !ThreadId -> !RetryStatus -> !UTCTime -> RestartResult -- | A stale DeadLetter was received. StaleDeadLetter :: !ThreadId -> !LetterEpoch -> !ChildEpoch -> !UTCTime -> RestartResult -- | The restart failed for a reason decribed by a SupervisionEvent RestartFailed :: SupervisionEvent -> RestartResult data DeadLetter class QueueLike q newQueueIO :: QueueLike q => Natural -> IO (q a) readQueue :: QueueLike q => q a -> STM a writeQueue :: QueueLike q => q a -> a -> STM () data SupervisionCtx q -- | Smart constructor which offers a default throttling based on fibonacci -- numbers. fibonacciRetryPolicy :: RetryPolicyM IO -- | 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. eventStream :: QueueLike q => Supervisor q -> q SupervisionEvent -- | Returns the number of active threads at a given moment in time. activeChildren :: QueueLike q => Supervisor q -> IO Int -- | 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. shutdownSupervisor :: QueueLike q => Supervisor q -> IO () -- | Fork a thread in a supervised mode. forkSupervised :: QueueLike q => Supervisor q -> RetryPolicyM IO -> IO () -> 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. monitorWith :: QueueLike q => RetryPolicyM IO -> Supervisor q -> Supervisor q -> IO ThreadId module Control.Concurrent.Supervisor type Supervisor = Supervisor TQueue type Child = Child_ TQueue newSupervisor :: RestartStrategy -> IO Supervisor -- | Erlang inspired strategies. At the moment only the OneForOne is -- implemented. data RestartStrategy OneForOne :: RestartStrategy data SupervisionEvent ChildBorn :: !ThreadId -> !UTCTime -> SupervisionEvent ChildDied :: !ThreadId -> !SomeException -> !UTCTime -> SupervisionEvent ChildRestarted :: !ThreadId -> !ThreadId -> !RetryStatus -> !UTCTime -> SupervisionEvent ChildNotFound :: !ThreadId -> !UTCTime -> SupervisionEvent StaleDeadLetterReceived :: !ThreadId -> !LetterEpoch -> !ChildEpoch -> !UTCTime -> SupervisionEvent ChildRestartLimitReached :: !ThreadId -> !RetryStatus -> !UTCTime -> SupervisionEvent ChildFinished :: !ThreadId -> !UTCTime -> SupervisionEvent type RestartAction = ThreadId -> IO ThreadId data Child_ q data RestartResult -- | The supervised Child_ was restarted successfully. Restarted :: !ThreadId -> !ThreadId -> !RetryStatus -> !UTCTime -> RestartResult -- | A stale DeadLetter was received. StaleDeadLetter :: !ThreadId -> !LetterEpoch -> !ChildEpoch -> !UTCTime -> RestartResult -- | The restart failed for a reason decribed by a SupervisionEvent RestartFailed :: SupervisionEvent -> RestartResult data DeadLetter class QueueLike q newQueueIO :: QueueLike q => Natural -> IO (q a) readQueue :: QueueLike q => q a -> STM a writeQueue :: QueueLike q => q a -> a -> STM () data SupervisionCtx q -- | Smart constructor which offers a default throttling based on fibonacci -- numbers. fibonacciRetryPolicy :: RetryPolicyM IO -- | 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. eventStream :: QueueLike q => Supervisor q -> q SupervisionEvent -- | Returns the number of active threads at a given moment in time. activeChildren :: QueueLike q => Supervisor q -> IO Int -- | 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. shutdownSupervisor :: QueueLike q => Supervisor q -> IO () -- | Fork a thread in a supervised mode. forkSupervised :: QueueLike q => Supervisor q -> RetryPolicyM IO -> IO () -> 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. monitorWith :: QueueLike q => RetryPolicyM IO -> Supervisor q -> Supervisor q -> IO ThreadId