Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data LooperDef m = LooperDef {}
- seconds :: Double -> NominalDiffTime
- minutes :: Double -> NominalDiffTime
- hours :: Double -> NominalDiffTime
- data LooperFlags = LooperFlags {}
- getLooperFlags :: String -> Parser LooperFlags
- data LooperEnvironment = LooperEnvironment {}
- getLooperEnvironment :: String -> String -> IO LooperEnvironment
- readLooperEnvironment :: String -> String -> [(String, String)] -> LooperEnvironment
- looperEnvironmentParser :: String -> Parser Error LooperEnvironment
- data LooperConfiguration = LooperConfiguration {}
- data LooperSettings = LooperSettings {}
- deriveLooperSettings :: NominalDiffTime -> NominalDiffTime -> LooperFlags -> LooperEnvironment -> Maybe LooperConfiguration -> LooperSettings
- mkLooperDef :: Text -> LooperSettings -> m () -> LooperDef m
- runLoopers :: MonadUnliftIO m => [LooperDef m] -> m ()
- runLoopersIgnoreOverrun :: (MonadUnliftIO m, MonadUnliftIO n) => (LooperDef m -> n ()) -> [LooperDef m] -> n ()
- runLoopersRaw :: (MonadUnliftIO m, MonadUnliftIO n) => (LooperDef m -> n ()) -> (LooperDef m -> n ()) -> [LooperDef m] -> n ()
- waitNominalDiffTime :: MonadIO m => NominalDiffTime -> m ()
Documentation
A looper definition
LooperDef | |
|
Instances
Generic (LooperDef m) Source # | |
type Rep (LooperDef m) Source # | |
Defined in Looper type Rep (LooperDef m) = D1 ('MetaData "LooperDef" "Looper" "looper-0.2.0.1-KtHCFq9jvmIIOmRdmTjfbR" 'False) (C1 ('MetaCons "LooperDef" 'PrefixI 'True) ((S1 ('MetaSel ('Just "looperDefName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "looperDefEnabled") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :*: (S1 ('MetaSel ('Just "looperDefPeriod") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NominalDiffTime) :*: (S1 ('MetaSel ('Just "looperDefPhase") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NominalDiffTime) :*: S1 ('MetaSel ('Just "looperDefFunc") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m ())))))) |
seconds :: Double -> NominalDiffTime Source #
Construct a NominalDiffTime
from a number of seconds
minutes :: Double -> NominalDiffTime Source #
Construct a NominalDiffTime
from a number of minutes
hours :: Double -> NominalDiffTime Source #
Construct a NominalDiffTime
from a number of hours
data LooperFlags Source #
A structure to parse command-line flags for a looper into
Instances
:: String | The name of the looper (best to make this all-lowercase) |
-> Parser LooperFlags |
An optparse applicative parser for LooperFlags
data LooperEnvironment Source #
A structure to parse environment variables for a looper into
Instances
:: String | Prefix for each variable (best to make this all-caps) |
-> String | Name of the looper (best to make this all-caps too) |
-> IO LooperEnvironment |
Get a LooperEnvironment
from the environment
readLooperEnvironment Source #
:: String | Prefix for each variable (best to make this all-caps) |
-> String | Name of the looper (best to make this all-caps too) |
-> [(String, String)] | |
-> LooperEnvironment |
Get a LooperEnvironment
from a pure environment
looperEnvironmentParser Source #
:: String | Name of the looper (best to make this all-caps) |
-> Parser Error LooperEnvironment |
An envparse
parser for a LooperEnvironment
data LooperConfiguration Source #
A structure to configuration for a looper into
Instances
data LooperSettings Source #
Settings that you might want to pass into a looper using mkLooperDef
Instances
:: NominalDiffTime | Default phase |
-> NominalDiffTime | Default period |
-> LooperFlags | |
-> LooperEnvironment | |
-> Maybe LooperConfiguration | |
-> LooperSettings |
:: Text | Name |
-> LooperSettings | |
-> m () | The function to loop |
-> LooperDef m |
runLoopers :: MonadUnliftIO m => [LooperDef m] -> m () Source #
Simply run loopers
runLoopers = runLoopersIgnoreOverrun looperDefFunc
Note that this function will loop forever, you need to wrap it using async
yourself.
runLoopersIgnoreOverrun Source #
:: (MonadUnliftIO m, MonadUnliftIO n) | |
=> (LooperDef m -> n ()) | Custom runner |
-> [LooperDef m] | Loopers |
-> n () |
Run loopers with a custom runner, ignoring any overruns
runLoopersIgnoreOverrun = runLoopersRaw (pure ())
see runLoopersRaw
Note that this function will loop forever, you need to wrap it using async
yourself.
:: (MonadUnliftIO m, MonadUnliftIO n) | |
=> (LooperDef m -> n ()) | Overrun handler |
-> (LooperDef m -> n ()) | Runner |
-> [LooperDef m] | Loopers |
-> n () |
Run loopers, with a custom runner and overrun handler
- The overrun handler is run when the looper function takes longer than its period. You can use this to log a warning, for example.
- The runner function is used to run the looper function
You can use
looperDefFunc
:: LooperDef m -> m ()
to run aLooperDef
, and you can wrap this function in some custom logic before you pass it intorunLoopersRaw
In this manner you can add logging or metrics, for example.
Note that this function will loop forever, you need to wrap it using async
yourself.
waitNominalDiffTime :: MonadIO m => NominalDiffTime -> m () Source #
Wait for a given NominalDiffTime
This takes care of the conversion to microseconds to pass to threadDelay
for you.
waitNominalDiffTime ndt = liftIO $ threadDelay $ round (toRational ndt * (1000 * 1000))