timers-0.2.0.1: Simple package that implements timers.

Safe HaskellSafe-Inferred

Control.Concurrent.Timer

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 IOSource

Utility

oneShotTimerSource

Arguments

:: IO ()

The action to be executed.

-> Delay

The (minimal) time until the execution in microseconds.

-> IO TimerIO 

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

oneShotStartSource

Arguments

:: TimerIO 
-> IO ()

The action the timer will start with.

-> Delay

The dealy the timer will start with.

-> IO 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 already initialized, it the previous timer will be stoped (the thread killed) and the timer will be started anew.

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

oneShotRestart :: TimerIO -> IO BoolSource

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 restrat was successful, otherwise (e.g. other thread is attempting to manipulate the timer or the timer was not initialized) returns False.

repeatedTimerSource

Arguments

:: IO ()

The action to be executed.

-> Delay

The (minimal) delay between executions.

-> IO TimerIO 

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

repeatedStartSource

Arguments

:: TimerIO 
-> IO ()

The action the timer will start with.

-> Delay

The dealy the timer will start with.

-> IO 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 already initialized, it the previous timer will be stoped (the thread killed) and the timer will be started anew.

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

repeatedRestart :: TimerIO -> IO BoolSource

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 restrat was successful, otherwise (e.g. other thread is attempting to manipulate the timer or the timer was not initialized) returns False.

newTimer :: IO TimerIOSource

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

stopTimer :: TimerIO -> IO ()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).