Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
-
class
Monad
m =>
MonadDelay
m
where
- threadDelay :: DiffTime -> m ()
-
class
(
MonadSTM
m,
MonadDelay
m) =>
MonadTimer
m
where
- data Timeout m :: Type
- newTimeout :: DiffTime -> m ( Timeout m)
- readTimeout :: Timeout m -> STM m TimeoutState
- updateTimeout :: Timeout m -> DiffTime -> m ()
- cancelTimeout :: Timeout m -> m ()
- awaitTimeout :: Timeout m -> STM m Bool
- registerDelay :: DiffTime -> m ( TVar m Bool )
- timeout :: DiffTime -> m a -> m ( Maybe a)
- data TimeoutState
- data DiffTime
- diffTimeToMicrosecondsAsInt :: DiffTime -> Int
- microsecondsAsIntToDiffTime :: Int -> DiffTime
Documentation
class Monad m => MonadDelay m where Source #
Nothing
threadDelay :: DiffTime -> m () Source #
default threadDelay :: MonadTimer m => DiffTime -> m () Source #
Instances
class ( MonadSTM m, MonadDelay m) => MonadTimer m where Source #
newTimeout :: DiffTime -> m ( Timeout m) Source #
Create a new timeout which will fire at the given time duration in the future.
The timeout will start in the
TimeoutPending
state and either
fire at or after the given time leaving it in the
TimeoutFired
state,
or it may be cancelled with
cancelTimeout
, leaving it in the
TimeoutCancelled
state.
Timeouts cannot be reset to the pending state once fired or cancelled (as this would be very racy). You should create a new timeout if you need this functionality.
readTimeout :: Timeout m -> STM m TimeoutState Source #
Read the current state of a timeout. This does not block, but returns
the current state. It is your responsibility to use
retry
to wait.
Alternatively you may wish to use the convenience utility
awaitTimeout
to wait for just the fired or cancelled outcomes.
You should consider the cancelled state if you plan to use
cancelTimeout
.
updateTimeout :: Timeout m -> DiffTime -> m () Source #
cancelTimeout :: Timeout m -> m () Source #
Cancel a timeout (unless it has already fired), putting it into the
TimeoutCancelled
state. Code reading and acting on the timeout state
need to handle such cancellation appropriately.
It is safe to race this concurrently against the timer firing. It will have no effect if the timer fires first.
awaitTimeout :: Timeout m -> STM m Bool Source #
Returns
True
when the timeout is fired, or
False
if it is cancelled.
Instances
This is a length of time, as measured by a clock. Conversion functions will treat it as seconds. It has a precision of 10^-12 s.