packages feed

theatre-dev 0.4 → 0.4.0.1

raw patch · 2 files changed

+29/−2 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ TheatreDev.Daemon: Config :: state -> (state -> IO state) -> (state -> IO ()) -> Config
+ TheatreDev.Daemon: [$sel:cleanUp:Config] :: Config -> state -> IO ()
+ TheatreDev.Daemon: [$sel:initialState:Config] :: Config -> state
+ TheatreDev.Daemon: [$sel:iterate:Config] :: Config -> state -> IO state
+ TheatreDev.Daemon: data Config

Files

library/TheatreDev/Daemon.hs view
@@ -2,6 +2,7 @@   ( Daemon,      -- * Acquisition+    Config (..),     spawn,      -- * Control@@ -13,10 +14,25 @@ import TheatreDev.Prelude import TheatreDev.Wait qualified as Wait +-- | Configuration of the daemon behaviour. data Config = forall state.   Config-  { initialState :: state,+  { -- | Initial state of the daemon.+    initialState :: 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.     iterate :: state -> IO state,+    -- | Clean up after the iteration loop is stopped.+    -- You can use that to release resources or+    -- issue notifications about the daemon dying.     cleanUp :: state -> IO ()   } @@ -49,6 +65,8 @@         wait = Wait.all (fmap (.wait) daemons)       } +-- | Fork a thread to run the daemon loop on+-- returning immediately with a handle to control it. spawn :: Config -> IO Daemon spawn Config {..} = do   iteratingVar <- newTVarIO True@@ -77,10 +95,19 @@       }   where +-- | 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'. kill :: Daemon -> IO () kill daemon =   atomically daemon.kill +-- | 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. wait :: Daemon -> IO () wait daemon =   atomically daemon.wait >>= maybe (pure ()) throwIO
theatre-dev.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name:          theatre-dev-version:       0.4+version:       0.4.0.1 category:      Concurrency, Actors synopsis:      Minimalistic actor library experiments description: