data-effects-0.4.0.2: A basic framework for effect systems based on effects represented by GADTs.
Copyright(c) 2024-2025 Sayo contributors
LicenseMPL-2.0 (see the file LICENSE)
Maintainerymdfield@outlook.jp
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Effect.Concurrent.Timer

Description

Effects for controlling time-related operations.

Synopsis

Documentation

data Timer :: Effect where Source #

An effect for time-related operations.

Constructors

Clock :: Timer f DiffTime

Retrieves the current relative time from an arbitrary fixed reference point. The reference point does not change within the context of that scope.

Sleep :: DiffTime -> Timer f ()

Temporarily suspends computation for the specified duration.

Instances

Instances details
FirstOrder Timer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

HFunctor Timer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

Methods

hfmap :: (forall x. f x -> g x) -> Timer f a -> Timer g a #

type LabelOf Timer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

type OrderOf Timer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

sleep'_ :: forall f es ff c. (Free c ff, f ~ Eff ff es, In Timer es) => DiffTime -> f () Source #

Temporarily suspends computation for the specified duration.

sleep'' :: forall tag f es ff c. (Free c ff, f ~ Eff ff es, (:>) (Tagged tag Timer) es) => DiffTime -> f () Source #

Temporarily suspends computation for the specified duration.

sleep' :: forall key f es ff c. (Free c ff, f ~ Eff ff es, Has key Timer es) => DiffTime -> f () Source #

Temporarily suspends computation for the specified duration.

sleep :: forall f es ff c. (Free c ff, f ~ Eff ff es, (:>) Timer es) => DiffTime -> f () Source #

Temporarily suspends computation for the specified duration.

clock'_ :: forall f es ff c. (Free c ff, f ~ Eff ff es, In Timer es) => 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 tag f es ff c. (Free c ff, f ~ Eff ff es, (:>) (Tagged tag Timer) es) => 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 key f es ff c. (Free c ff, f ~ Eff ff es, Has key Timer es) => 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 f es ff c. (Free c ff, f ~ Eff ff es, (:>) Timer es) => 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.

withElapsedTime Source #

Arguments

:: forall a es ff c. (Timer :> es, Monad (Eff ff es), Free c ff) 
=> (Eff ff es DiffTime -> Eff ff es a)

A scope where the elapsed time can be obtained. An action to retrieve the elapsed time is passed as an argument.

-> Eff ff es 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 :: forall a es ff c. (Timer :> es, Monad (Eff ff es), Free c ff) => Eff ff es a -> Eff ff es (DiffTime, a) Source #

Returns the time taken for a computation along with the result as a pair.

sleepUntil :: forall es ff c. (Timer :> es, Monad (Eff ff es), Free c ff) => DiffTime -> Eff ff es (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.

runCyclic Source #

Arguments

:: forall a es ff c. (Timer :> es, Monad (Eff ff es), Free c ff) 
=> Eff ff es DiffTime

An action called at the start of each loop to determine the time interval until the next loop. For example, pure 1 would control the loop to have a 1-second interval.

-> Eff ff es ()

The computation to repeat.

-> Eff ff es 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.

runPeriodic Source #

Arguments

:: forall a es ff c. (Timer :> es, Monad (Eff ff es), Free c ff) 
=> DiffTime

Loop interval

-> Eff ff es ()

The computation to repeat.

-> Eff ff es a 

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 :: forall a es ff c. (Timer :> es, Yield () () :> es, Monad (Eff ff es), Free c ff) => DiffTime -> Eff ff es 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.

cyclicTimer :: forall a es ff c. (Timer :> es, Yield () DiffTime :> es, Monad (Eff ff es), Free c ff) => Eff ff es a Source #

Calls yield of a coroutine at specific intervals. Controls so that the time returned by yield becomes the time interval until the next loop. If the computation time exceeds and the requested interval cannot be realized, the excess delay occurs, which accumulates and is not canceled.

data CyclicTimer :: Effect 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 f ()

Controls the wait time so that when wait is executed repeatedly, the specified time becomes the interval until the next wait.

Instances

Instances details
FirstOrder CyclicTimer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

HFunctor CyclicTimer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

Methods

hfmap :: (forall x. f x -> g x) -> CyclicTimer f a -> CyclicTimer g a #

type LabelOf CyclicTimer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

type OrderOf CyclicTimer Source # 
Instance details

Defined in Data.Effect.Concurrent.Timer

wait'_ :: forall f es ff c. (Free c ff, f ~ Eff ff es, In CyclicTimer es) => DiffTime -> f () Source #

Controls the wait time so that when wait is executed repeatedly, the specified time becomes the interval until the next wait.

wait'' :: forall tag f es ff c. (Free c ff, f ~ Eff ff es, (:>) (Tagged tag CyclicTimer) es) => DiffTime -> f () Source #

Controls the wait time so that when wait is executed repeatedly, the specified time becomes the interval until the next wait.

wait' :: forall key f es ff c. (Free c ff, f ~ Eff ff es, Has key CyclicTimer es) => DiffTime -> f () Source #

Controls the wait time so that when wait is executed repeatedly, the specified time becomes the interval until the next wait.

wait :: forall f es ff c. (Free c ff, f ~ Eff ff es, (:>) CyclicTimer es) => DiffTime -> f () Source #

Controls the wait time so that when wait is executed repeatedly, the specified time becomes the interval until the next wait.

runTimerIO :: forall a ff es c. (Emb IO :> es, Monad (Eff ff es), Free c ff) => Eff ff (Timer ': es) a -> Eff ff es a Source #

restartClock :: forall a ff es c. (Timer :> es, Monad (Eff ff es), Free c ff) => Eff ff es a -> Eff ff es a Source #

Re-zeros the clock time in the local scope.