timers-0.2.0.4: Simple package that implements timers.

Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.Timer.Lifted

Synopsis

Documentation

data Timer m Source #

The data type representing the timer. For now, the action and delay are fixed for the lifetime of the Timer.

type TimerIO = Timer IO Source #

Utility

oneShotTimer Source #

Arguments

:: MonadBaseControl IO m 
=> m ()

The action to be executed.

-> Delay

The (minimal) time until the execution in microseconds.

-> m (Timer m) 

Executes the the given action once after the given delay elapsed, no sooner, maybe later.

oneShotStart Source #

Arguments

:: MonadBaseControl IO m 
=> Timer m 
-> m ()

The action the timer will start with.

-> Delay

The dealy the timer will start with.

-> m Bool 

Attempts to start a timer. The started timer will have the given delay and action associated and will be one-shot timer.

If the timer was initialized before it will be stopped (killed) and started anew.

Returns True if the start was successful, otherwise (e.g. other thread is attempting to manipulate the timer) returns False.

oneShotRestart :: MonadBaseControl IO m => Timer m -> m Bool Source #

Attempts to restart already initialized timer. The restarted timer will have the same delay and action associated and will be one-shot timer.

Returns True if the restart was successful, otherwise (e.g. other thread is attempting to manipulate the timer or the timer was not initialized) returns False.

repeatedTimer Source #

Arguments

:: MonadBaseControl IO m 
=> m ()

The action to be executed.

-> Delay

The (minimal) delay between executions.

-> m (Timer m) 

Executes the the given action repeatedly with at least the given delay between executions.

repeatedStart Source #

Arguments

:: MonadBaseControl IO m 
=> Timer m 
-> m ()

The action the timer will start with.

-> Delay

The dealy the timer will start with.

-> m Bool 

Attempts to start a timer. The started timer will have the given delay and action associated and will be repeated timer.

If the timer was initialized before it will be stopped (killed) and started anew.

Returns True if the start was successful, otherwise (e.g. other thread is attempting to manipulate the timer) returns False.

repeatedRestart :: MonadBaseControl IO m => Timer m -> m Bool Source #

Attempts to restart already initialized timer. The restarted timer will have the same delay and action associated and will be one-shot timer.

Returns True if the restart was successful, otherwise (e.g. other thread is attempting to manipulate the timer or the timer was not initialized) returns False.

newTimer :: MonadBase IO m => m (Timer m) Source #

Creates a new timer. This does not start the timer.

stopTimer :: MonadBaseControl IO m => Timer m -> m () Source #

This function is blocking. It waits until it can stop the timer (until there is a value in the MVar), then it kills the timer's thread.

After this action completes, the Timer is not innitialized anymore (the MVar contains Nothing).