time-out-0.2: Timers, timeouts, alarms, monadic wrappers

Safe HaskellNone




Manage an alarm clock running in a dedicated thread.

You specify an amount of time. The alarm clock waits for that amount of time, and then throws an exception back to you, to notify you the time has passed. You can stop and restart it at any time.

This is simply a convenient wrapper over Control.Timer, offered here becuase a common use of timers is to run actions with a time limit (timeout), and the API here makes it more straight-forward to do.



Creating and destroying alarm

newAlarm :: (TimeUnit t, MonadIO m) => t -> m Alarm Source

withAlarm :: (TimeUnit t, MonadIO m, MonadMask m) => t -> (Alarm -> m a) -> m a Source

Starting an alarm

startAlarm :: MonadIO m => Alarm -> m () Source

startAlarm' :: (TimeUnit t, MonadIO m) => Alarm -> t -> m () Source

Stopping a alarm

stopAlarm :: MonadIO m => Alarm -> m () Source

Restarting a alarm

restartAlarm' :: (TimeUnit t, MonadIO m) => Alarm -> t -> m () Source

Higher level functions

alarm :: (MonadIO m, MonadCatch m) => Alarm -> m a -> m (Maybe a) Source

alarm' :: (TimeUnit t, MonadIO m, MonadCatch m) => Alarm -> t -> m a -> m (Maybe a) Source