module Control.Concurrent.Async.Timer.Unsafe
( Timer
, defaultTimerConf
, timerConfSetInitDelay
, timerConfSetInterval
, withAsyncTimer
, timerWait
) where
import Control.Concurrent.Async.Lifted
import Control.Concurrent.Async.Timer.Internal
import Control.Concurrent.Lifted
import Control.Exception.Safe
import Control.Monad.Trans.Control
withAsyncTimer :: (MonadBaseControl IO m, MonadMask m)
=> TimerConf -> (Timer -> m b) -> m b
withAsyncTimer conf io = do
mVar <- newEmptyMVar
let timer = Timer { timerMVar = mVar }
initDelay = _timerConfInitDelay conf
intervalDelay = _timerConfInterval conf
withAsync (timerThread initDelay intervalDelay mVar) $ \asyncHandle -> do
link asyncHandle
io timer `finally` cancelWith asyncHandle TimerEnd