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

Data.Effect.Concurrent.Timer

Description

Effects for controlling time-related operations.

Synopsis

Documentation

data Timer a where Source #

An effect for time-related operations.

Constructors

Clock :: Timer 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 ()

Temporarily suspends computation for the specified duration.

pattern LSleep :: forall a f. () => (a ~ (), ()) => DiffTime -> LiftFOE Timer f a Source #

pattern LClock :: forall a f. () => (a ~ DiffTime, ()) => LiftFOE Timer f a Source #

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.

withElapsedTime Source #

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.

runCyclic Source #

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, pure 1 would control the loop to have a 1-second interval.

-> 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.

runPeriodic Source #

Arguments

:: (Timer <: m, Monad m) 
=> DiffTime

Loop interval

-> m ()

The computation to repeat.

-> m 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 :: (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.

cyclicTimer :: (Timer <: m, Yield () DiffTime <: m, Monad m) => m 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 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 wait is executed repeatedly, the specified time becomes the interval until the next wait.

pattern LWait :: forall a f. () => (a ~ (), ()) => DiffTime -> LiftFOE CyclicTimer f a 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.

wait' :: forall {k} (tag :: k) f. SendFOE (Tag CyclicTimer tag) 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.

wait'' :: forall {k} (key :: k) f. SendFOEBy key 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.