delay-0: More useful and humain delaying functions

Safe HaskellNone





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.


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.


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

class AsMicro d where Source

Calculate the number of microseconds of delay a value represents. Instances must round up for correctness.


toMicro :: d -> Integer Source


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