io-classes-0.2.0.0: Type classes for concurrency with STM, ST and timing
Safe Haskell None
Language Haskell2010

Control.Monad.Class.MonadTimer

Synopsis

Documentation

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 #

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

Instances

Instances details
MonadTimer IO Source #
Instance details

Defined in Control.Monad.Class.MonadTimer

Associated Types

data Timeout IO Source #

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

Defined in Control.Monad.Class.MonadTimer

Associated Types

data Timeout ( ReaderT r m) Source #

MonadTimer m => MonadTimer ( StateT s m) Source #
Instance details

Defined in Control.Monad.Class.MonadTimer

Associated Types

data Timeout ( StateT s m) Source #

( Monoid w, MonadTimer m) => MonadTimer ( WriterT w m) Source #
Instance details

Defined in Control.Monad.Class.MonadTimer

Associated Types

data Timeout ( WriterT w m) Source #

( Monoid w, MonadTimer m) => MonadTimer ( RWST r w s m) Source #
Instance details

Defined in Control.Monad.Class.MonadTimer

Associated Types

data Timeout ( RWST r w s m) Source #

data DiffTime Source #

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 Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c DiffTime Source #

toConstr :: DiffTime -> Constr Source #

dataTypeOf :: DiffTime -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c DiffTime ) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c DiffTime ) Source #

gmapT :: ( forall b. Data b => b -> b) -> DiffTime -> DiffTime Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> DiffTime -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> DiffTime -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> DiffTime -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> DiffTime -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> DiffTime -> m DiffTime Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> DiffTime -> m DiffTime Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> DiffTime -> m DiffTime Source #

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

Show DiffTime
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

NFData DiffTime
Instance details

Defined in Data.Time.Clock.Internal.DiffTime