theatre-dev-0.4.0.1: Minimalistic actor library experiments
Safe HaskellSafe-Inferred
LanguageHaskell2010

TheatreDev.Daemon

Synopsis

Documentation

data Daemon Source #

Think of an actor that does not process any messages and simply interrupts between each iteration to check whether it's still alive.

Instances

Instances details
Monoid Daemon Source # 
Instance details

Defined in TheatreDev.Daemon

Semigroup Daemon Source # 
Instance details

Defined in TheatreDev.Daemon

Acquisition

data Config Source #

Configuration of the daemon behaviour.

Constructors

forall state. Config 

Fields

  • initialState :: state

    Initial state of the daemon.

  • iterate :: state -> IO state

    Iteration action, updating the daemon's state. It gets executed in a loop, with checks of whether the daemon is still alive after each one. Killing the daemon will not interrupt the currently ongoing iteration, thus providing gracefulness guarantees.

    If an exception is thrown by this action, the iteration loop will stop, the cleanUp action will get executed and in all place where wait is called the exception will be rethrown.

  • cleanUp :: state -> IO ()

    Clean up after the iteration loop is stopped. You can use that to release resources or issue notifications about the daemon dying.

spawn :: Config -> IO Daemon Source #

Fork a thread to run the daemon loop on returning immediately with a handle to control it.

Control

kill :: Daemon -> IO () Source #

Command the daemon to stop iterating, finish the ongoing iteration and execute the clean up action.

This action executes immediately. If you want to block waiting for the daemon to actually die, after kill you can run wait.

wait :: Daemon -> IO () Source #

Block waiting for the daemon to die either due to getting killed or due to its iterator action throwing an exception. The exception will get rethrown here.