| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Concurrent.Extended
Synopsis
- sleep :: DiffTime -> IO ()
- forkImmortal :: ForkableMonadIO m => String -> Logger Hasura -> m Void -> m Thread
- data ThreadState
- newtype ThreadShutdown m = ThreadShutdown {
- tsThreadShutdown :: m ()
- forkManagedT :: ForkableMonadIO m => String -> Logger Hasura -> m Void -> ManagedT m Thread
- data Forever m = forall a. Forever a (a -> m a)
- forkManagedTWithGracefulShutdown :: ForkableMonadIO m => String -> Logger Hasura -> ThreadShutdown m -> m (Forever m) -> ManagedT m Thread
- data ImmortalThreadLog
- type ForkableMonadIO m = (MonadIO m, MonadBaseControl IO m, Forall (Pure m))
- forConcurrentlyEIO :: (MonadIO m, MonadError e m) => Int -> [a] -> (a -> ExceptT e IO b) -> m [b]
Documentation
sleep :: DiffTime -> IO () Source #
Like threadDelay, but takes a DiffTime instead of an Int microseconds.
NOTE: you cannot simply replace e.g. threadDelay 1000 with sleep 1000 since those literals
have different meanings!
Arguments
| :: ForkableMonadIO m | |
| => String | A label describing this thread's function (see |
| -> Logger Hasura | |
| -> m Void | An IO action we expect never to return normally. This will have the type
signature ':: m a' (see e.g. the type of |
| -> m Thread | A handle for the forked thread. See Control.Immortal. |
Note: Please consider using forkManagedT instead to ensure reliable
resource cleanup.
data ThreadState Source #
Constructors
| ThreadForked | |
| ThreadBlocking | |
| ThreadShutdownInitiated |
Instances
| Eq ThreadState Source # | |
Defined in Control.Concurrent.Extended | |
| Show ThreadState Source # | |
Defined in Control.Concurrent.Extended Methods showsPrec :: Int -> ThreadState -> ShowS # show :: ThreadState -> String # showList :: [ThreadState] -> ShowS # | |
newtype ThreadShutdown m Source #
ThreadShutdown is a newtype wrapper over an action which is intended
to execute when a thread's shutdown is initiated before killing the thread
Constructors
| ThreadShutdown | |
Fields
| |
forkManagedT :: ForkableMonadIO m => String -> Logger Hasura -> m Void -> ManagedT m Thread Source #
This function pairs a call to forkImmortal with a finalizer which stops
the immortal thread.
The Forever type defines an infinite looping monadic action (like m void), but allows the
caller to control the recursion or insert code before each iteration. The a is the initial argument,
and subsequent iterations will be fed the argument returned by the previous one. See
forkManagedTWithGracefulShutdown to see how it's used
Constructors
| forall a. Forever a (a -> m a) |
forkManagedTWithGracefulShutdown :: ForkableMonadIO m => String -> Logger Hasura -> ThreadShutdown m -> m (Forever m) -> ManagedT m Thread Source #
forkManagedTWithGracefulShutdown is an extension of the forkManagedT
function this function also attempts to gracefully shutdown the thread. This function
accepts a `m (Forever m)` argument. The Forever type contains a function and an argument
to the function. The function supplied will be run repeatedly until shutdown is initiated. The
response of the function will be the argument to the next iteration.
For reference, this function is used to run the async actions processor. Check
asyncActionsProcessor
data ImmortalThreadLog Source #
Constructors
| ImmortalThreadUnexpectedException String SomeException | Synchronous Exception |
| ImmortalThreadStopping String | Asynchronous Exception about to be sent |
| ImmortalThreadRestarted String |
Instances
| ToEngineLog ImmortalThreadLog Hasura Source # | |
Defined in Control.Concurrent.Extended Methods toEngineLog :: ImmortalThreadLog -> (LogLevel, EngineLogType Hasura, Value) Source # | |
type ForkableMonadIO m = (MonadIO m, MonadBaseControl IO m, Forall (Pure m)) Source #
Like MonadIO but constrained to stacks in which forking a new thread is reasonable/safe.
In particular StateT causes problems.
This is the constraint you can use for functions that call async, or immortal.
forConcurrentlyEIO :: (MonadIO m, MonadError e m) => Int -> [a] -> (a -> ExceptT e IO b) -> m [b] Source #
A somewhat wonky function for parallelizing for xs f where f is
(MonadIO m, MonadError e m). This is equivalent to for xs f modulo the
IO effects (i.e. when the IO has no real side effects we care about).
This also takes a chunkSize argument so you can manipulate the amount of
work given to each thread.