time-manager-0.2.4: Scalable timer

Safe Haskell | None
Language | Haskell2010

System.ThreadManager

Contents

- Fork
- Synchronization
- Re-exports

Description

A thread manager including a time manager. The manager has responsibility to kill managed threads.

Synopsis

- data ThreadManager
- newThreadManager :: Manager -> IO ThreadManager
- stopAfter :: ThreadManager -> IO a -> (Maybe SomeException -> IO ()) -> IO a
- data KilledByThreadManager = KilledByThreadManager (Maybe SomeException)
- forkManaged :: ThreadManager -> String -> IO () -> IO ()
- forkManagedFinally :: ThreadManager -> String -> IO () -> IO () -> IO ()
- forkManagedUnmask :: ThreadManager -> String -> ((forall x. IO x -> IO x) -> IO ()) -> IO ()
- forkManagedTimeout :: ThreadManager -> String -> (Handle -> IO ()) -> IO ()
- forkManagedTimeoutFinally :: ThreadManager -> String -> (Handle -> IO ()) -> IO () -> IO ()
- waitUntilAllGone :: ThreadManager -> IO ()
- isAllGone :: ThreadManager -> STM Bool
- data Manager
- withHandle :: ThreadManager -> TimeoutAction -> (Handle -> IO a) -> IO (Maybe a)
- data Handle
- tickle :: Handle -> IO ()
- pause :: Handle -> IO ()
- resume :: Handle -> IO ()

# Documentation

data ThreadManager Source #

Manager to manage the thread and the timer.

newThreadManager :: Manager -> IO ThreadManager Source #

Starting a thread manager. Its action is initially set to 'return ()' and should be set by `setAction`. This allows that the action can include the manager itself.

stopAfter :: ThreadManager -> IO a -> (Maybe SomeException -> IO ()) -> IO a Source #

Stopping the manager.

The action is run in the scope of an exception handler that catches all exceptions (including asynchronous ones); this allows the cleanup handler to cleanup in all circumstances. If an exception is caught, it is rethrown after the cleanup is complete.

data KilledByThreadManager Source #

An exception used internally to kill a managed thread.

Constructors

KilledByThreadManager (Maybe SomeException) |

#### Instances

Instances details

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

# Fork

forkManaged Source #

Arguments

:: ThreadManager |
-> String | Thread name
-> IO () | Action
-> IO () |

Fork a managed thread.

This guarantees that the thread ID is added to the manager's queue before the thread starts, and is removed again when the thread terminates (normally or abnormally).

forkManagedFinally :: ThreadManager -> String -> IO () -> IO () -> IO () Source #

Fork a managed thread with a cleanup function.

forkManagedUnmask :: ThreadManager -> String -> ((forall x. IO x -> IO x) -> IO ()) -> IO () Source #

Like `forkManaged`, but run action with exceptions masked

forkManagedTimeout :: ThreadManager -> String -> (Handle -> IO ()) -> IO () Source #

Fork a managed thread with a handle created by a timeout manager.

forkManagedTimeoutFinally :: ThreadManager -> String -> (Handle -> IO ()) -> IO () -> IO () Source #

Fork a managed thread with a handle created by a timeout manager and with a cleanup function.

# Synchronization

waitUntilAllGone :: ThreadManager -> IO () Source #

Wait until all managed thread are finished.

isAllGone :: ThreadManager -> STM Bool Source #

# Re-exports

data Manager Source #

A timeout manager

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

data Handle Source #

A handle used by a timeout manager.

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`.