Copyright | (c) Tim Watson 2012 |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | Tim Watson <watson.timothy@gmail.com> |
Stability | experimental |
Portability | non-portable (requires concurrency) |
Safe Haskell | None |
Language | Haskell98 |
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.
- type TimerRef = ProcessId
- data Tick = Tick
- sleep :: TimeInterval -> Process ()
- sleepFor :: Int -> TimeUnit -> Process ()
- sendAfter :: NFSerializable a => TimeInterval -> ProcessId -> a -> Process TimerRef
- runAfter :: TimeInterval -> Process () -> Process TimerRef
- exitAfter :: Serializable a => TimeInterval -> ProcessId -> a -> Process TimerRef
- killAfter :: TimeInterval -> ProcessId -> String -> Process TimerRef
- startTimer :: NFSerializable a => TimeInterval -> ProcessId -> a -> Process TimerRef
- ticker :: TimeInterval -> ProcessId -> Process TimerRef
- periodically :: TimeInterval -> Process () -> Process TimerRef
- resetTimer :: TimerRef -> Process ()
- cancelTimer :: TimerRef -> Process ()
- flushTimer :: (Serializable a, Eq a) => TimerRef -> a -> Delay -> Process ()
Documentation
represents a tick
event that timers can generate
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.
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!