distributed-process-extras-0.2.1.1: Cloud Haskell Extras

Copyright(c) Tim Watson 2012
LicenseBSD3 (see the file LICENSE)
MaintainerTim Watson <watson.timothy@gmail.com>
Stabilityexperimental
Portabilitynon-portable (requires concurrency)
Safe HaskellNone
LanguageHaskell98

Control.Distributed.Process.Extras.Timer

Description

Provides an API for running code or sending messages, either after some initial delay or periodically, and for cancelling, re-setting and/or flushing pending timers.

Synopsis

Documentation

type TimerRef = ProcessId Source

an opaque reference to a timer

data Tick Source

represents a tick event that timers can generate

Constructors

Tick 

sleep :: TimeInterval -> Process () Source

blocks the calling Process for the specified TimeInterval. Note that this function assumes that a blocking receive is the most efficient approach to acheiving this, however the runtime semantics (particularly with regards scheduling) should not differ from threadDelay in practise.

sleepFor :: Int -> TimeUnit -> Process () Source

Literate way of saying sleepFor 3 Seconds.

sendAfter :: NFSerializable a => TimeInterval -> ProcessId -> a -> Process TimerRef Source

starts a timer which sends the supplied message to the destination process after the specified time interval.

runAfter :: TimeInterval -> Process () -> Process TimerRef Source

runs the supplied process action(s) after t has elapsed

exitAfter :: Serializable a => TimeInterval -> ProcessId -> a -> Process TimerRef Source

calls exit pid reason after t has elapsed

killAfter :: TimeInterval -> ProcessId -> String -> Process TimerRef Source

kills the specified process after t has elapsed

startTimer :: NFSerializable a => TimeInterval -> ProcessId -> a -> Process TimerRef Source

starts a timer that repeatedly sends the supplied message to the destination process each time the specified time interval elapses. To stop messages from being sent in future, cancelTimer can be called.

ticker :: TimeInterval -> ProcessId -> Process TimerRef Source

sets up a timer that sends Tick repeatedly at intervals of t

periodically :: TimeInterval -> Process () -> Process TimerRef Source

runs the supplied process action(s) repeatedly at intervals of t

resetTimer :: TimerRef -> Process () Source

resets a running timer. Note: Cancelling a timer does not guarantee that all its messages are prevented from being delivered to the target process. Also note that resetting an ongoing timer (started using the startTimer or periodically functions) will only cause the current elapsed period to time out, after which the timer will continue running. To stop a long-running timer permanently, you should use cancelTimer instead.

cancelTimer :: TimerRef -> Process () Source

permanently cancels a timer

flushTimer :: (Serializable a, Eq a) => TimerRef -> a -> Delay -> Process () Source

cancels a running timer and flushes any viable timer messages from the process' message queue. This function should only be called by the process expecting to receive the timer's messages!