| Copyright | (c) David Janssen 2019 |
|---|---|
| License | MIT |
| Maintainer | janssen.dhj@gmail.com |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
KMonad.Util
Contents
Description
Contains code for making it slighly easier to work with time, errors, and Acquire datatypes.
Synopsis
- data Milliseconds
- tDiff :: SystemTime -> SystemTime -> Milliseconds
- onErr :: (MonadUnliftIO m, Exception e) => m Int -> e -> m ()
- using :: Acquire a -> ContT r (RIO e) a
- logRethrow :: HasLogFunc e => Text -> SomeException -> RIO e a
- withLaunch :: HasLogFunc e => Text -> RIO e a -> (Async a -> RIO e b) -> RIO e b
- withLaunch_ :: HasLogFunc e => Text -> RIO e a -> RIO e b -> RIO e b
- launch :: HasLogFunc e => Text -> RIO e a -> ContT r (RIO e) (Async a)
- launch_ :: HasLogFunc e => Text -> RIO e a -> ContT r (RIO e) ()
Time units and utils
data Milliseconds Source #
Newtype wrapper around Int to add type safety to our time values
Instances
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
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
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.
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
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
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