Copyright | (c) 2024 Sayo Koyoneda |
---|---|
License | MPL-2.0 (see the file LICENSE) |
Maintainer | ymdfield@outlook.jp |
Safe Haskell | None |
Language | GHC2021 |
Data.Effect.Concurrent.Timer
Description
Effects for controlling time-related operations.
Synopsis
- data Timer a where
- type LTimer = LiftFOE Timer
- pattern LSleep :: forall a f. () => (a ~ (), ()) => DiffTime -> LiftFOE Timer f a
- pattern LClock :: forall a f. () => (a ~ DiffTime, ()) => LiftFOE Timer f a
- clock :: SendFOE Timer f => f DiffTime
- clock' :: forall {k} (tag :: k) f. SendFOE (Tag Timer tag) f => f DiffTime
- clock'' :: forall {k} (key :: k) f. SendFOEBy key Timer f => f DiffTime
- sleep :: SendFOE Timer f => DiffTime -> f ()
- sleep' :: forall {k} (tag :: k) f. SendFOE (Tag Timer tag) f => DiffTime -> f ()
- sleep'' :: forall {k} (key :: k) f. SendFOEBy key Timer f => DiffTime -> f ()
- withElapsedTime :: (Timer <: m, Monad m) => (m DiffTime -> m a) -> m a
- measureTime :: (Timer <: m, Monad m) => m a -> m (DiffTime, a)
- sleepUntil :: (Timer <: m, Monad m) => DiffTime -> m (Maybe DiffTime)
- runCyclic :: (Timer <: m, Monad m) => m DiffTime -> m () -> m a
- runPeriodic :: (Timer <: m, Monad m) => DiffTime -> m () -> m a
- periodicTimer :: (Timer <: m, Yield () () <: m, Monad m) => DiffTime -> m a
- cyclicTimer :: (Timer <: m, Yield () DiffTime <: m, Monad m) => m a
- data CyclicTimer a where
- Wait :: DiffTime -> CyclicTimer ()
- type LCyclicTimer = LiftFOE CyclicTimer
- pattern LWait :: forall a f. () => (a ~ (), ()) => DiffTime -> LiftFOE CyclicTimer f a
- wait :: SendFOE CyclicTimer f => DiffTime -> f ()
- wait' :: forall {k} (tag :: k) f. SendFOE (Tag CyclicTimer tag) f => DiffTime -> f ()
- wait'' :: forall {k} (key :: k) f. SendFOEBy key CyclicTimer f => DiffTime -> f ()
Documentation
An effect for time-related operations.
clock :: SendFOE Timer f => f DiffTime Source #
Retrieves the current relative time from an arbitrary fixed reference point. The reference point does not change within the context of that scope.
clock' :: forall {k} (tag :: k) f. SendFOE (Tag Timer tag) f => f DiffTime Source #
Retrieves the current relative time from an arbitrary fixed reference point. The reference point does not change within the context of that scope.
clock'' :: forall {k} (key :: k) f. SendFOEBy key Timer f => f DiffTime Source #
Retrieves the current relative time from an arbitrary fixed reference point. The reference point does not change within the context of that scope.
sleep :: SendFOE Timer f => DiffTime -> f () Source #
Temporarily suspends computation for the specified duration.
sleep' :: forall {k} (tag :: k) f. SendFOE (Tag Timer tag) f => DiffTime -> f () Source #
Temporarily suspends computation for the specified duration.
sleep'' :: forall {k} (key :: k) f. SendFOEBy key Timer f => DiffTime -> f () Source #
Temporarily suspends computation for the specified duration.
Arguments
:: (Timer <: m, Monad m) | |
=> (m DiffTime -> m a) | A scope where the elapsed time can be obtained. An action to retrieve the elapsed time is passed as an argument. |
-> m a |
Creates a scope where elapsed time can be obtained. An action to retrieve the elapsed time, re-zeroed at the start of the scope, is passed to the scope.
measureTime :: (Timer <: m, Monad m) => m a -> m (DiffTime, a) Source #
Returns the time taken for a computation along with the result as a pair.
sleepUntil :: (Timer <: m, Monad m) => DiffTime -> m (Maybe DiffTime) Source #
Temporarily suspends computation until the relative time from the fixed reference point in the current scope's context, as given by the argument.
If the specified resume time has already passed, returns the elapsed time (positive value) in Just
.
Arguments
:: (Timer <: m, Monad m) | |
=> m DiffTime | An action called at the start of each loop to determine the time interval until the next loop.
For example, |
-> m () | The computation to repeat. |
-> m a |
Repeats a computation indefinitely. Controls so that each loop occurs at a specific time interval. If the computation time exceeds and the requested interval cannot be realized, the excess delay occurs, which accumulates and is not canceled.
Controls to repeat a specified computation at fixed time intervals. A specialized version of runCyclic
.
If the computation time exceeds and the requested interval cannot be realized, the excess delay occurs, which accumulates and is not canceled.
periodicTimer :: (Timer <: m, Yield () () <: m, Monad m) => DiffTime -> m a Source #
Calls yield
of a coroutine at fixed intervals.
If the computation time exceeds and the requested interval cannot be realized, the excess delay occurs, which accumulates and is not canceled.
data CyclicTimer a where Source #
An effect that realizes control of wait times such that the specified time becomes the interval until the next wait
when wait
is executed repeatedly.
Constructors
Wait :: DiffTime -> CyclicTimer () | Controls the wait time so that when |
type LCyclicTimer = LiftFOE CyclicTimer Source #
wait :: SendFOE CyclicTimer f => DiffTime -> f () Source #
Controls the wait time so that when wait
is executed repeatedly, the specified time becomes the interval until the next wait
.