network-mux
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.JobPool

Description

This module allows the management of a multiple Async jobs which are grouped by an 'Ord group => group' type.

Synopsis

Documentation

data JobPool (q :: HasQueue) group (m :: Type -> Type) a Source #

JobPool allows to submit asynchronous jobs, wait for their completion or cancel. Jobs are grouped, each group can be cancelled separately.

data HasQueue Source #

Whether a JobPool was created with a completion queue. Only a WithQueue pool can be passed to waitForJob.

Constructors

WithQueue 
WithoutQueue 

data Job group (m :: Type -> Type) a Source #

An asynchronous job which belongs to some group and its exception handler.

Constructors

Job 

Fields

withJobPool :: forall group m a b. (MonadAsync m, MonadThrow m, MonadLabelledSTM m) => (JobPool 'WithQueue group m a -> m b) -> m b Source #

withJobPool_ :: forall group m a b. (MonadAsync m, MonadThrow m, MonadLabelledSTM m) => (JobPool 'WithoutQueue group m a -> m b) -> m b Source #

Like withJobPool, but for a pool whose jobs' results nobody ever inspects: no TQueue is created, so there is nothing for forkJob/ forkJobOn to write a finished job's result into, and nothing to remember to drain. waitForJob does not typecheck against a pool created this way.

forkJob :: forall (q :: HasQueue) group m a. (MonadAsync m, MonadMask m, Ord group) => JobPool q group m a -> Job group m a -> m () Source #

Fork a Job using async.

forkJobOn :: forall (q :: HasQueue) group m a. (MonadAsync m, MonadMask m, Ord group) => Int -> JobPool q group m a -> Job group m a -> m () Source #

Fork a Job using asyncOn.

readSize :: forall (m :: Type -> Type) (q :: HasQueue) group a. MonadSTM m => JobPool q group m a -> STM m Int Source #

readGroupSize :: forall (m :: Type -> Type) group (q :: HasQueue) a. (MonadSTM m, Eq group) => JobPool q group m a -> group -> STM m Int Source #

waitForJob :: forall (m :: Type -> Type) group a. MonadSTM m => JobPool 'WithQueue group m a -> STM m a Source #

Wait for next successfully completed job. Unlike wait it will not throw if a job errors.

cancelGroup :: forall m group (q :: HasQueue) a. (MonadAsync m, Eq group) => JobPool q group m a -> group -> m () Source #

Cancel all threads in a given group. Blocks until all threads terminated.