Safe Haskell | None |
---|---|
Language | Haskell2010 |
- delay :: (MonadIO m, AsMicro period) => period -> m ()
- delayTill :: MonadIO m => UTCTime -> m ()
- timeout :: (MonadIO m, MonadMask m, AsMicro period) => period -> m a -> m (Maybe a)
- timeoutAt :: (MonadIO m, MonadMask m) => UTCTime -> m a -> m (Maybe a)
- type CallbackKey = MVar CallbackHandle
- callbackAfter :: (MonadIO m, AsMicro period) => period -> IO () -> m CallbackKey
- callbackAt :: MonadIO m => UTCTime -> IO () -> m CallbackKey
- updateCallbackToAfter :: (MonadIO m, AsMicro period) => CallbackKey -> period -> m ()
- updateCallbackTo :: MonadIO m => CallbackKey -> UTCTime -> m ()
- cancelCallback :: MonadIO m => CallbackKey -> m ()
- class AsMicro d where
Delays
delay :: (MonadIO m, AsMicro period) => period -> m () Source
Delay a until at least the specified amount of time has passed.
delayTill :: MonadIO m => UTCTime -> m () Source
Delay until a specific UTCTime
has occured (at least once).
This is slighly confusing, as we can't guarantee we don't return only after the second
occurence of the UTCTime
under certain leap second handling regimes. Consider for example
when delayTill
is called during a leap second occurence, where the system clock jumps back
and repeats the second. As there is no indication the time has already passed once, we must
wait until the second occurence.
Timeouts
timeout :: (MonadIO m, MonadMask m, AsMicro period) => period -> m a -> m (Maybe a) Source
Run an monad action for at least a specific number of seconds, but not much more.
timeoutAt :: (MonadIO m, MonadMask m) => UTCTime -> m a -> m (Maybe a) Source
Run a monadic action until it produces a result or a specific time occures. Leap second handling as per delayTill.
Callbacks
type CallbackKey = MVar CallbackHandle Source
We hold the CallbackHandle in an MVar so we don't race on update/cancelation and executing the callback. Updating or canceling holds the lock, which is also required to export the action.
callbackAfter :: (MonadIO m, AsMicro period) => period -> IO () -> m CallbackKey Source
Run a callback after a period of time has passed.
callbackAt :: MonadIO m => UTCTime -> IO () -> m CallbackKey Source
Run a callback at a specific time.
updateCallbackToAfter :: (MonadIO m, AsMicro period) => CallbackKey -> period -> m () Source
Change an existing, unexecuted or canceled callbak to run after a specific period of time
from the call of updateCallbackToAfter
.
updateCallbackTo :: MonadIO m => CallbackKey -> UTCTime -> m () Source
Change an existing, unexecuted or canceled callbak to run after at a specific time.
cancelCallback :: MonadIO m => CallbackKey -> m () Source
Terminate an unexecuted callback.
Time period conversion
Calculate the number of microseconds of delay a value represents. Instances must round up for correctness.
AsMicro Double Source | As seconds. |
AsMicro Float Source | As seconds. |
AsMicro Int Source | As seconds. |
AsMicro Int8 Source | As seconds. |
AsMicro Int16 Source | As seconds. |
AsMicro Int32 Source | As seconds. |
AsMicro Int64 Source | As seconds. |
AsMicro Integer Source | As seconds. |
AsMicro Word Source | As seconds. |
AsMicro Word8 Source | As seconds. |
AsMicro Word16 Source | As seconds. |
AsMicro Word32 Source | As seconds. |
AsMicro Word64 Source | As seconds. |
AsMicro Natural Source | As seconds. |
AsMicro DiffTime Source | |
HasResolution d => AsMicro (Fixed d) Source | As seconds. |
(Fractional n, AsMicro n) => AsMicro (Time n) Source |