| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Monad.Class.MonadTimer
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 #
Minimal complete definition
Nothing
Methods
threadDelay :: DiffTime -> m () Source #
default threadDelay :: MonadTimer m => DiffTime -> m () Source #
Instances
| MonadDelay IO Source # | With |
Defined in Control.Monad.Class.MonadTimer Methods threadDelay :: DiffTime -> IO () Source # | |
| MonadDelay m => MonadDelay (ReaderT r m) Source # | |
Defined in Control.Monad.Class.MonadTimer Methods threadDelay :: DiffTime -> ReaderT r m () Source # | |
class (MonadSTM m, MonadDelay m) => MonadTimer m where Source #
Minimal complete definition
newTimeout, readTimeout, updateTimeout, cancelTimeout, timeout
Methods
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
| MonadTimer IO Source # | |
Defined in Control.Monad.Class.MonadTimer Methods newTimeout :: DiffTime -> IO (Timeout IO) Source # readTimeout :: Timeout IO -> STM IO TimeoutState Source # updateTimeout :: Timeout IO -> DiffTime -> IO () Source # cancelTimeout :: Timeout IO -> IO () Source # awaitTimeout :: Timeout IO -> STM IO Bool Source # | |
| (MonadTimer m, MonadFork m) => MonadTimer (ReaderT r m) Source # | |
Defined in Control.Monad.Class.MonadTimer Methods newTimeout :: DiffTime -> ReaderT r m (Timeout (ReaderT r m)) Source # readTimeout :: Timeout (ReaderT r m) -> STM (ReaderT r m) TimeoutState Source # updateTimeout :: Timeout (ReaderT r m) -> DiffTime -> ReaderT r m () Source # cancelTimeout :: Timeout (ReaderT r m) -> ReaderT r m () Source # awaitTimeout :: Timeout (ReaderT r m) -> STM (ReaderT r m) Bool Source # registerDelay :: DiffTime -> ReaderT r m (TVar (ReaderT r m) Bool) Source # timeout :: DiffTime -> ReaderT r m a -> ReaderT r m (Maybe a) Source # | |
data TimeoutState Source #
Constructors
| TimeoutPending | |
| TimeoutFired | |
| TimeoutCancelled |
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.
Instances
| Enum DiffTime | |
Defined in Data.Time.Clock.Internal.DiffTime | |
| Eq DiffTime | |
| Fractional DiffTime | |
| Data DiffTime | |
Defined in Data.Time.Clock.Internal.DiffTime Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DiffTime -> c DiffTime # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c DiffTime # toConstr :: DiffTime -> Constr # dataTypeOf :: DiffTime -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c DiffTime) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DiffTime) # gmapT :: (forall b. Data b => b -> b) -> DiffTime -> DiffTime # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DiffTime -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DiffTime -> r # gmapQ :: (forall d. Data d => d -> u) -> DiffTime -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> DiffTime -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> DiffTime -> m DiffTime # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DiffTime -> m DiffTime # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DiffTime -> m DiffTime # | |
| Num DiffTime | |
Defined in Data.Time.Clock.Internal.DiffTime | |
| Ord DiffTime | |
Defined in Data.Time.Clock.Internal.DiffTime | |
| Real DiffTime | |
Defined in Data.Time.Clock.Internal.DiffTime Methods toRational :: DiffTime -> Rational # | |
| RealFrac DiffTime | |
| Show DiffTime | |
| NFData DiffTime | |
Defined in Data.Time.Clock.Internal.DiffTime | |