-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Provides API for timer based execution of IO actions
--   
--   This is a lightweight package built on top of the async package
--   providing easy to use periodic timers. This can be used for executing
--   IO actions periodically.
@package async-timer
@version 0.1.4.1

module Control.Concurrent.Async.Timer.Unsafe

-- | This is the type of timer handle, which will be provided to the IO
--   action to be executed within <tt>withAsyncTimer</tt>. The user can use
--   <a>timerWait</a> on this timer to delay execution until the next timer
--   synchronization event.
data Timer

-- | Default timer configuration specifies no initial delay and an interval
--   delay of 1s.
defaultTimerConf :: TimerConf

-- | Set the initial delay in the provided timer configuration.
timerConfSetInitDelay :: Int -> TimerConf -> TimerConf

-- | Set the interval delay in the provided timer configuration.
timerConfSetInterval :: Int -> TimerConf -> TimerConf

-- | 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 <a>timerWait</a> on it for synchronization. When the
--   provided IO action has terminated, the timer thread will be terminated
--   also.
withAsyncTimer :: (MonadBaseControl IO m, MonadMask m) => TimerConf -> (Timer -> m b) -> m b

-- | Wait for the next synchronization event on the givem timer.
timerWait :: MonadBaseControl IO m => Timer -> m ()

module Control.Concurrent.Async.Timer

-- | This is the type of timer handle, which will be provided to the IO
--   action to be executed within <tt>withAsyncTimer</tt>. The user can use
--   <a>timerWait</a> on this timer to delay execution until the next timer
--   synchronization event.
data Timer

-- | Default timer configuration specifies no initial delay and an interval
--   delay of 1s.
defaultTimerConf :: TimerConf

-- | Set the initial delay in the provided timer configuration.
timerConfSetInitDelay :: Int -> TimerConf -> TimerConf

-- | Set the interval delay in the provided timer configuration.
timerConfSetInterval :: Int -> TimerConf -> TimerConf

-- | 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 <a>timerWait</a> on it for synchronization. When the
--   provided IO action has terminated, the timer thread will be terminated
--   also.
--   
--   This functions requires the contraint <tt><a>Forall</a> (<a>Pure</a>
--   m)</tt>, which means that the monad <tt>m</tt> needs to satisfy
--   <tt><a>StM</a> m a ~ a</tt> for all <tt>a</tt>.
withAsyncTimer :: (MonadBaseControl IO m, MonadMask m, Forall (Pure m)) => TimerConf -> (Timer -> m b) -> m b

-- | Wait for the next synchronization event on the givem timer.
timerWait :: MonadBaseControl IO m => Timer -> m ()
