metronome-0.1.1: Time Synchronized execution.

Copyright(c) Paolo Veronelli 2012
LicenseBSD-style (see the file LICENSE)
Maintainerpaolo.veronelli@gmail.com
Stabilityunstable
Portabilitynot portable (requires STM)
Safe HaskellNone
LanguageHaskell98

System.Metronome

Contents

Description

Synchronized execution of sequences of actions, controlled in STM

All data structures are made accessible via Data.Lens abstraction.

Actions to be executed are of type Action = STM (IO ()). At each tick, the scheduled actions are ordered by priority, binded as STM actions ignoring the retrying ones. The results, being IO actions are executed in that order.

Every Track and Metronome lives in its own thread and can be stopped or killed as such, setting a flag in its state.

Track and metronome state are exposed in TVar value to be modified at will. The only closed and inaccessible value is the synchronizing channel, written by the metronome and waited by tracks. The TrackForker returned by a metronome function is closing this channel and it's the only way to fork a track.

See System.Metronome.Practical for an simple wrapper around this module.

Synopsis

Data structures

data Track Source

State of a track.

Constructors

Track 

Fields

_sync :: Ticks

the number of ticks elapsed from the track fork

_frequency :: Frequency

calling frequency relative to metronome ticks frequency

_actions :: [Action]

the actions left to be run

_priority :: Priority

priority of this track among its peers

_muted :: Bool

muted flag, when True, actions are not scheduled, just skipped

data Thread a Source

supporting values with running and alive flag

Constructors

Thread 

Fields

_running :: Bool

stopped or running flag

_alive :: Bool

set to false to require kill thread

_core :: a

core data

data Metronome Source

State of a metronome

Constructors

Metronome 

Fields

_ticks :: [MTime]

next ticking times

_schedule :: [(Priority, Action)]

actions scheduled for the tick to come

Lenses

running :: forall a. Lens (Thread a) Bool Source

alive :: forall a. Lens (Thread a) Bool Source

core :: forall a. Lens (Thread a) a Source

Synonyms

type Control a = TVar (Thread a) Source

A Thread value cell in STM

type Priority = Double Source

Priority values between tracks under the same metronome.

type Frequency = Integer Source

Number of metronome ticks between two track ticks

type Ticks = Integer Source

Number of elapsed ticks

type Action = STM (IO ()) Source

Track effect interface. Write in STM the collective and spit out the IO action to be executed when all STMs for this tick are done or retried

type MTime = Double Source

Time, in seconds

type TrackForker = Control Track -> IO () Source

The action to fork a new track from a track state.

API

metronome Source

Arguments

:: Control Metronome

initial state

-> IO TrackForker 

Fork a metronome from its initial state