Copyright | (c) Moritz Clasmeier 2016 2018 |
---|---|
License | BSD3 |
Maintainer | mtesseract@silverratio.net |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module exports the public API for asynchronous timers.
- data Timer
- data TimerConf
- defaultConf :: TimerConf
- setInitDelay :: Int -> TimerConf -> TimerConf
- setInterval :: Int -> TimerConf -> TimerConf
- withAsyncTimer :: (MonadUnliftIO m, MonadMask m) => TimerConf -> (Timer -> m b) -> m b
- wait :: MonadUnliftIO m => Timer -> m ()
- reset :: MonadUnliftIO m => Timer -> m ()
Documentation
This is the type of timer handle, which will be provided to the
IO action to be executed within withAsyncTimer
. The user can use
timerWait
on this timer to delay execution until the next timer
synchronization event.
defaultConf :: TimerConf Source #
Default timer configuration specifies no initial delay and an interval delay of 1s.
setInitDelay :: Int -> TimerConf -> TimerConf Source #
Set the initial delay in the provided timer configuration.
setInterval :: Int -> TimerConf -> TimerConf Source #
Set the interval delay in the provided timer configuration.
withAsyncTimer :: (MonadUnliftIO m, MonadMask m) => TimerConf -> (Timer -> m b) -> m b Source #
Spawn a timer thread based on the provided timer configuration
and then run the provided IO action, which receives the new timer
as an argument and call timerWait
on it for synchronization. When
the provided IO action has terminated, the timer thread will be
terminated also.
wait :: MonadUnliftIO m => Timer -> m () Source #
Wait for the next synchronization event on the givem timer.
reset :: MonadUnliftIO m => Timer -> m () Source #
Reset the provided timer.