time-manager-0.2.4: Scalable timer

Safe Haskell | None
Language | Haskell2010

System.TimeManager

Contents

- Types
- Manager
- Registering a timeout action
- Control timeout
- Low level
- Exceptions

Synopsis

- data Manager
- defaultManager :: Manager
- type TimeoutAction = IO ()
- data Handle
- emptyHandle :: Handle
- initialize :: Int -> IO Manager
- stopManager :: Manager -> IO ()
- killManager :: Manager -> IO ()
- withManager :: Int -> (Manager -> IO a) -> IO a
- withManager' :: Int -> (Manager -> IO a) -> IO a
- withHandle :: Manager -> TimeoutAction -> (Handle -> IO a) -> IO (Maybe a)
- withHandleKillThread :: Manager -> TimeoutAction -> (Handle -> IO ()) -> IO ()
- tickle :: Handle -> IO ()
- pause :: Handle -> IO ()
- resume :: Handle -> IO ()
- register :: Manager -> TimeoutAction -> IO Handle
- registerKillThread :: Manager -> TimeoutAction -> IO Handle
- cancel :: Handle -> IO ()
- data TimeoutThread = TimeoutThread

## Types

data Manager Source #

A timeout manager

defaultManager :: Manager Source #

No manager.

type TimeoutAction = IO () Source #

An action to be performed on timeout.

data Handle Source #

A handle used by a timeout manager.

emptyHandle :: Handle Source #

## Manager

initialize :: Int -> IO Manager Source #

Creating timeout manager which works every N microseconds where N is the first argument.

stopManager :: Manager -> IO () Source #

Stopping timeout manager with onTimeout fired.

killManager :: Manager -> IO () Source #

Killing timeout manager immediately without firing onTimeout.

withManager Source #

Arguments

:: Int | timeout in microseconds
-> (Manager -> IO a) |
-> IO a |

Call the inner function with a timeout manager. `stopManager` is used after that.

withManager' Source #

Arguments

:: Int | timeout in microseconds
-> (Manager -> IO a) |
-> IO a |

Call the inner function with a timeout manager. `killManager` is used after that.

## Registering a timeout action

withHandle :: Manager -> TimeoutAction -> (Handle -> IO a) -> IO (Maybe a) Source #

Registering a timeout action and unregister its handle when the body action is finished. `Nothing` is returned on timeout.

withHandleKillThread :: Manager -> TimeoutAction -> (Handle -> IO ()) -> IO () Source #

Registering a timeout action of killing this thread and unregister its handle when the body action is killed or finished.

## Control timeout

tickle :: Handle -> IO () Source #

Setting the state to active. `Manager` turns active to inactive repeatedly.

pause :: Handle -> IO () Source #

Setting the state to paused. `Manager` does not change the value.

resume :: Handle -> IO () Source #

Setting the paused state to active. This is an alias to `tickle`.

## Low level

register :: Manager -> TimeoutAction -> IO Handle Source #

Registering a timeout action.

registerKillThread :: Manager -> TimeoutAction -> IO Handle Source #

Registering a timeout action of killing this thread. `TimeoutThread` is thrown to the thread which called this function on timeout. Catch `TimeoutThread` if you don't want to leak the asynchronous exception to GHC RTS.

cancel :: Handle -> IO () Source #

Removing the `Handle` from the `Manager` immediately.

## Exceptions

data TimeoutThread Source #

The asynchronous exception thrown if a thread is registered via `registerKillThread`.

Constructors

TimeoutThread |

#### Instances

Instances details

Exception TimeoutThread Source # |
Instance details Defined in System.TimeManager Methods toException :: TimeoutThread -> SomeException Source # fromException :: SomeException -> Maybe TimeoutThread Source # displayException :: TimeoutThread -> String Source # backtraceDesired :: TimeoutThread -> Bool Source #
Show TimeoutThread Source # |
Instance details Defined in System.TimeManager Methods showsPrec :: Int -> TimeoutThread -> ShowS Source # show :: TimeoutThread -> String Source # showList :: [TimeoutThread] -> ShowS Source #