si-timers-1.2.0.0: timers using SI units (seconds)
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.Class.MonadTimer.SI

Synopsis

Type classes

class (MonadDelay m, MonadMonotonicTime m) => MonadDelay m where Source #

Methods

threadDelay :: DiffTime -> m () Source #

Instances

Instances details
MonadDelay IO Source #

Thread delay. When the delay is smaller than what Int can represent it will use the threadDelay (e.g. for the IO monad it will use threadDelay); otherwise it will recursively call threadDelay.

Instance details

Defined in Control.Monad.Class.MonadTimer.SI

Methods

threadDelay :: DiffTime -> IO () Source #

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

Defined in Control.Monad.Class.MonadTimer.SI

Methods

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

class (MonadTimer m, MonadMonotonicTime m) => MonadTimer m where Source #

Methods

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

A register delay function which safe on 32-bit systems.

registerDelayCancellable :: DiffTime -> m (STM m TimeoutState, m ()) Source #

A cancellable register delay which is safe on 32-bit systems and efficient for delays smaller than what Int can represent (especially on systems which support native timer manager).

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

A timeout function.

TODO: IO instance is not safe on 32-bit systems.

Instances

Instances details
MonadTimer IO Source #

Like registerDelay but safe on 32-bit systems. When the delay is larger than what Int can represent it will fork a thread which will write to the returned TVar once the delay has passed. When the delay is small enough it will use the MonadTimer's registerDelay (e.g. for IO monad it will use the GHC's registerDelay).

TODO: timeout not safe on 32-bit systems.

Instance details

Defined in Control.Monad.Class.MonadTimer.SI

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

Defined in Control.Monad.Class.MonadTimer.SI

Auxiliary functions

diffTimeToMicrosecondsAsInt :: DiffTime -> Int Source #

Convert DiffTime in seconds to microseconds represented by an Int.

Note that on 32bit systems it can only represent `2^31-1` seconds, which is only ~35 minutes.

microsecondsAsIntToDiffTime :: Int -> DiffTime Source #

Convert time in microseconds in DiffTime (measured in seconds).

Re-exports

data DiffTime #

This is a length of time, as measured by a clock. Conversion functions such as fromInteger and realToFrac will treat it as seconds. For example, (0.010 :: DiffTime) corresponds to 10 milliseconds.

It has a precision of one picosecond (= 10^-12 s). Enumeration functions will treat it as picoseconds.

Instances

Instances details
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 #

Enum DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Num DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Read DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Fractional 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 -> () #

Eq DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

Ord DiffTime 
Instance details

Defined in Data.Time.Clock.Internal.DiffTime

NoThunks DiffTime 
Instance details

Defined in NoThunks.Class

class MonadThread m => MonadFork (m :: Type -> Type) #

Minimal complete definition

forkIO, forkOn, forkIOWithUnmask, throwTo, yield

Instances

Instances details
MonadFork IO 
Instance details

Defined in Control.Monad.Class.MonadFork

Methods

forkIO :: IO () -> IO (ThreadId IO) #

forkOn :: Int -> IO () -> IO (ThreadId IO) #

forkIOWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO (ThreadId IO) #

throwTo :: Exception e => ThreadId IO -> e -> IO () #

killThread :: ThreadId IO -> IO () #

yield :: IO () #

MonadFork m => MonadFork (ReaderT e m) 
Instance details

Defined in Control.Monad.Class.MonadFork

Methods

forkIO :: ReaderT e m () -> ReaderT e m (ThreadId (ReaderT e m)) #

forkOn :: Int -> ReaderT e m () -> ReaderT e m (ThreadId (ReaderT e m)) #

forkIOWithUnmask :: ((forall a. ReaderT e m a -> ReaderT e m a) -> ReaderT e m ()) -> ReaderT e m (ThreadId (ReaderT e m)) #

throwTo :: Exception e0 => ThreadId (ReaderT e m) -> e0 -> ReaderT e m () #

killThread :: ThreadId (ReaderT e m) -> ReaderT e m () #

yield :: ReaderT e m () #

class Monad m => MonadTime (m :: Type -> Type) #

Minimal complete definition

getCurrentTime

Instances

Instances details
MonadTime IO 
Instance details

Defined in Control.Monad.Class.MonadTime

MonadTime m => MonadTime (ReaderT r m) 
Instance details

Defined in Control.Monad.Class.MonadTime

Default implementations

defaultRegisterDelay :: forall m timeout. (MonadFork m, MonadMonotonicTime m, MonadSTM m) => NewTimeout m timeout -> AwaitTimeout m timeout -> DiffTime -> m (TVar m Bool) Source #

A default implementation of registerDelay which supports delays longer then Int; this is especially important on 32-bit systems where maximum delay expressed in microseconds is around 35 minutes.

defaultRegisterDelayCancellable :: forall m timeout. (MonadFork m, MonadMonotonicTime m, MonadSTM m) => NewTimeout m timeout -> ReadTimeout m timeout -> CancelTimeout m timeout -> AwaitTimeout m timeout -> DiffTime -> m (STM m TimeoutState, m ()) Source #

A cancellable register delay which is safe on 32-bit systems and efficient for delays smaller than what Int can represent (especially on systems which support native timer manager).