module Arbiter.Worker.WorkerState
( WorkerState (..)
, newWorkerState
, signalShutdown
) where
import Control.Concurrent.STM (TVar)
import Control.Concurrent.STM qualified as STM
newWorkerState :: IO (TVar WorkerState)
newWorkerState :: IO (TVar WorkerState)
newWorkerState = WorkerState -> IO (TVar WorkerState)
forall a. a -> IO (TVar a)
STM.newTVarIO WorkerState
Running
signalShutdown :: TVar WorkerState -> IO ()
signalShutdown :: TVar WorkerState -> IO ()
signalShutdown TVar WorkerState
st = STM () -> IO ()
forall a. STM a -> IO a
STM.atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TVar WorkerState -> WorkerState -> STM ()
forall a. TVar a -> a -> STM ()
STM.writeTVar TVar WorkerState
st WorkerState
ShuttingDown
data WorkerState
=
Running
|
Paused
|
ShuttingDown
deriving stock (WorkerState -> WorkerState -> Bool
(WorkerState -> WorkerState -> Bool)
-> (WorkerState -> WorkerState -> Bool) -> Eq WorkerState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WorkerState -> WorkerState -> Bool
== :: WorkerState -> WorkerState -> Bool
$c/= :: WorkerState -> WorkerState -> Bool
/= :: WorkerState -> WorkerState -> Bool
Eq, Int -> WorkerState -> ShowS
[WorkerState] -> ShowS
WorkerState -> String
(Int -> WorkerState -> ShowS)
-> (WorkerState -> String)
-> ([WorkerState] -> ShowS)
-> Show WorkerState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WorkerState -> ShowS
showsPrec :: Int -> WorkerState -> ShowS
$cshow :: WorkerState -> String
show :: WorkerState -> String
$cshowList :: [WorkerState] -> ShowS
showList :: [WorkerState] -> ShowS
Show)