theatre-dev-0.5.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

spawn Source #

Arguments

:: state

Initial state of the daemon.

-> (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 places where wait is called the exception will be rethrown.

-> (state -> IO ())

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

-> IO Daemon 

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 and execute its cleanUp action either due to getting killed or due to its iterate action throwing an exception. The exception will get rethrown here.