io-sim-classes-0.2.0.0: Type classes for concurrency with STM, ST and timing
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Class.MonadTimer

Synopsis

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

Instances details
MonadDelay IO Source #

With threadDelay one can use arbitrary large DiffTimes, which is an advantage over threadDelay.

Instance details

Defined in Control.Monad.Class.MonadTimer

Methods

threadDelay :: DiffTime -> IO () Source #

MonadDelay m => MonadDelay (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Class.MonadTimer

Methods

threadDelay :: DiffTime -> ReaderT r m () Source #

class (MonadSTM m, MonadDelay m) => MonadTimer m where Source #

Associated Types

data Timeout m :: Type Source #

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.

registerDelay :: DiffTime -> m (TVar m Bool) Source #

default registerDelay :: MonadFork m => DiffTime -> m (TVar m Bool) Source #

timeout :: DiffTime -> m a -> m (Maybe a) Source #

data DiffTime #

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

Instances details
Enum DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Eq DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Fractional DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Data DiffTime 
Instance details

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 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Ord DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Real DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

RealFrac DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

properFraction :: Integral b => DiffTime -> (b, DiffTime) #

truncate :: Integral b => DiffTime -> b #

round :: Integral b => DiffTime -> b #

ceiling :: Integral b => DiffTime -> b #

floor :: Integral b => DiffTime -> b #

Show DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

NFData DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Methods

rnf :: DiffTime -> () #