control-event-0.2: Event scheduling system.ContentsIndex
Control.Event
Description

This module can execute events at specified time. It uses a two thread system that allows the STM adding and deleting of new threads without requiring later IO actions. An ability to place arbitrary event preprocessing when adding each event exists, but in a course grained manner. This feature can be expanded on request.

This is very like control-timeout, but was developed separately internal operation is similar with a thread sleeping via threadDelay and EventIds being based in part on expire time. It differs in that control-event is: * More complex * Requires initilization * Allows pure STM adding and removing of events (no post STM IO action) * Allows user control over event systems (can have more than one) * Allows events to run in event handler thread (advisable if thread spark is too expensive / computation is cheap) * No possible duplication of EventId (theoretical! no real advantage)

On the other hand, a shim could be made to provide the control-timeout API with Control.Event running under the hood.

Synopsis
data EventId
data EventSystem
initEventSystem :: IO EventSystem
addEvent :: EventSystem -> ClockTime -> IO () -> IO EventId
addEventSTM :: EventSystem -> ClockTime -> IO () -> STM EventId
cancelEvent :: EventSystem -> EventId -> IO Bool
cancelEventSTM :: EventSystem -> EventId -> STM Bool
evtSystemSize :: EventSystem -> STM Int
Documentation
data EventId
IDs the program can use to cancel previously scheduled events.
show/hide Instances
data EventSystem

A value indicating there is no such event.

The event system can either be initilized and passed as state or a global system can be declared using gEvtSys = unsafePeformIO initEventSystem

initEventSystem :: IO EventSystem
The only way to get an event system is to initilize one, which sets internal TVars and sparks two threads (one to expire events, one to look if you've added an event expiring before the current alarm).
addEvent :: EventSystem -> ClockTime -> IO () -> IO EventId
Add an *action* to be performed at *time* by *system*, returning a unique id.
addEventSTM :: EventSystem -> ClockTime -> IO () -> STM EventId
Atomically add an action to be performed at specified time and returning a unique id.
cancelEvent :: EventSystem -> EventId -> IO Bool
Cancel an event from the system, returning True on success.
cancelEventSTM :: EventSystem -> EventId -> STM Bool
Atomically cancel an event from the system, returning True on success.
evtSystemSize :: EventSystem -> STM Int
Produced by Haddock version 2.1.0