kmonad
Copyright(c) David Janssen 2019
LicenseMIT
Maintainerjanssen.dhj@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

KMonad.Util

Description

Contains code for making it slighly easier to work with time, errors, and Acquire datatypes.

Synopsis

Time units and utils

 

data Milliseconds Source #

Newtype wrapper around Int to add type safety to our time values

Instances

Instances details
Data Milliseconds Source # 
Instance details

Defined in KMonad.Util

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Milliseconds -> c Milliseconds #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Milliseconds #

toConstr :: Milliseconds -> Constr #

dataTypeOf :: Milliseconds -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Milliseconds) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Milliseconds) #

gmapT :: (forall b. Data b => b -> b) -> Milliseconds -> Milliseconds #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Milliseconds -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Milliseconds -> r #

gmapQ :: (forall d. Data d => d -> u) -> Milliseconds -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Milliseconds -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Milliseconds -> m Milliseconds #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Milliseconds -> m Milliseconds #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Milliseconds -> m Milliseconds #

Enum Milliseconds Source # 
Instance details

Defined in KMonad.Util

Generic Milliseconds Source # 
Instance details

Defined in KMonad.Util

Associated Types

type Rep Milliseconds :: Type -> Type #

Num Milliseconds Source # 
Instance details

Defined in KMonad.Util

Read Milliseconds Source # 
Instance details

Defined in KMonad.Util

Integral Milliseconds Source # 
Instance details

Defined in KMonad.Util

Real Milliseconds Source # 
Instance details

Defined in KMonad.Util

Show Milliseconds Source # 
Instance details

Defined in KMonad.Util

Eq Milliseconds Source # 
Instance details

Defined in KMonad.Util

Ord Milliseconds Source # 
Instance details

Defined in KMonad.Util

Display Milliseconds Source # 
Instance details

Defined in KMonad.Util

type Rep Milliseconds Source # 
Instance details

Defined in KMonad.Util

type Rep Milliseconds = D1 ('MetaData "Milliseconds" "KMonad.Util" "kmonad-0.4.4-inplace" 'True) (C1 ('MetaCons "Milliseconds" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMS") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

tDiff Source #

Arguments

:: SystemTime

The earlier timepoint

-> SystemTime

The later timepoint

-> Milliseconds

The time in milliseconds between the two

Calculate how much time has elapsed between 2 time points

Random utility helpers that have no better home

onErr :: (MonadUnliftIO m, Exception e) => m Int -> e -> m () Source #

A helper function that helps to throw errors when a return code is -1. Easiest when used as infix like this:

someFFIcall `onErr` MyCallFailedError someData

using :: Acquire a -> ContT r (RIO e) a Source #

Embed the action of using an Acquire in a continuation monad

logRethrow Source #

Arguments

:: HasLogFunc e 
=> Text 
-> SomeException

The error to throw

-> RIO e a 

Log an error message and then rethrow the error

Particularly useful as a suffix using catch. i.e.

doSomething `catch` logRethrow "I caught something"

Some helpers to launch background process

withLaunch Source #

Arguments

:: HasLogFunc e 
=> Text

The name of this process (for logging)

-> RIO e a

The action to repeat forever

-> (Async a -> RIO e b)

The foreground action to run

-> RIO e b

The resulting action

Launch a process that repeats an action indefinitely. If an error ever occurs, print it and rethrow it. Ensure the process is cleaned up upon error and/or shutdown.

withLaunch_ Source #

Arguments

:: HasLogFunc e 
=> Text

The name of this process (for logging)

-> RIO e a

The action to repeat forever

-> RIO e b

The foreground action to run

-> RIO e b

The resulting action

Like withLaunch, but without ever needing access to the async process

launch Source #

Arguments

:: HasLogFunc e 
=> Text

The name of this process (for logging)

-> RIO e a

The action to repeat forever

-> ContT r (RIO e) (Async a) 

Like withLaunch, but in the ContT monad

launch_ Source #

Arguments

:: HasLogFunc e 
=> Text

The name of this process (for logging)

-> RIO e a

The action to repeat forever

-> ContT r (RIO e) () 

Like withLaunch_, but in the ContT monad