| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.ThreadManager
Contents
Description
A thread manager including a time manager. The manager has responsibility to kill managed threads.
Because this is based on the accompanying System.TimeManager module, the same caveats apply:
- Only works for GHC.
- Only works with a threaded runtime.
- Users of older versions should check the current semantics.
- Using 32-bit systems means the max timeout is
(2147483647) microseconds, which is less than 36 minutes.maxBound:: Int - Using the same
Handlein different threads might cause issues in some edge cases. (i.e. using cancel/pause in one thread, and resume in another)
Synopsis
- data ThreadManager
- newThreadManager :: Manager -> IO ThreadManager
- stopAfter :: ThreadManager -> IO a -> (Maybe SomeException -> IO ()) -> IO a
- stopAfterWithResult :: ThreadManager -> IO a -> (Either SomeException a -> IO b) -> IO b
- 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 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 #
Create a thread manager.
To create a ThreadManager, you will first have to create a
Manager from the System.TimeManager module.
You can use either initialize or withManager.
stopAfter :: ThreadManager -> IO a -> (Maybe SomeException -> IO ()) -> IO a Source #
Stopping the manager.
stopAfter threadManager action cleanup
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.
stopAfterWithResult :: ThreadManager -> IO a -> (Either SomeException a -> IO b) -> IO b Source #
data KilledByThreadManager Source #
An exception used internally to kill a managed thread.
Constructors
| KilledByThreadManager (Maybe SomeException) |
Instances
| Exception KilledByThreadManager Source # | |
Defined in System.ThreadManager | |
| Show KilledByThreadManager Source # | |
Defined in System.ThreadManager Methods showsPrec :: Int -> KilledByThreadManager -> ShowS # show :: KilledByThreadManager -> String # showList :: [KilledByThreadManager] -> ShowS # | |
Fork
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).
Arguments
| :: ThreadManager | |
| -> String | Thread name |
| -> IO () | Action |
| -> IO () | Cleanup function |
| -> IO () |
Fork a managed thread with a cleanup function.
Arguments
| :: ThreadManager | |
| -> String | Thread name |
| -> ((forall x. IO x -> IO x) -> IO ()) | Action with unmask argument |
| -> IO () |
Like forkManaged, but run action with exceptions masked
Arguments
| :: ThreadManager | |
| -> String | Thread name |
| -> (Handle -> IO ()) | Action with timeout handle |
| -> IO () |
Fork a managed thread with a handle created by a timeout manager.
forkManagedTimeoutFinally Source #
Arguments
| :: ThreadManager | |
| -> String | Thread name |
| -> (Handle -> IO ()) | Action with timeout handle |
| -> IO () | Cleanup function |
| -> IO () |
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 threads are finished.
isAllGone :: ThreadManager -> STM Bool Source #
STM action that checks if all managed threads are finished.
Re-exports
withHandle :: ThreadManager -> TimeoutAction -> (Handle -> IO a) -> IO a Source #
Registering a TimeoutAction and unregister its Handle
when the body action is finished.
tickle :: Handle -> IO () Source #
Extending the timeout.
Careful: this does NOT reactivate an already paused Handle!