threads-pool-0.1: A library to operate with pool of haskell's IO threads

Control.Concurrent.Pool

Synopsis

Documentation

class (Monad m, MonadIO m) => Task m a r whereSource

Any monadic computation that can be turned to IO

Methods

runTask :: m r -> a -> IO rSource

Run the task with given argument

Instances

Task IO () r 
Task (ReaderT a IO) a r 
Task (StateT a IO) a r 

data Task m a r => Pool m a r Source

This stores all pool-related states

newPoolSource

Arguments

:: Task m a r 
=> Int

Number of threads in the pool

-> Bool

Should pool return tasks' results?

-> m (Pool m a r) 

Create new threads pool

newPoolIOSource

Arguments

:: Task m a r 
=> Int

Number of threads in the pool

-> Bool

Should pool return tasks' results?

-> IO (Pool m a r) 

Create new threads pool in IO monad

isPoolWaitingSource

Arguments

:: Task m a r 
=> Pool m a r

The pool

-> IO Bool 

Check if pool is waiting for new tasks

queueSource

Arguments

:: Task m a r 
=> Pool m a r

Pool of threads

-> m r

Task (monadic computation)

-> a

Argument for that computation

-> m Integer

Returns a number of task in the pool

Put the new task into queue

noMoreTasks :: Task m a r => Pool m a r -> m ()Source

Tell to the pool that there will no new tasks

noMoreTasksIO :: Task m a r => Pool m a r -> IO ()Source

Tell to the pool that there will no new tasks, in IO monad

readResultSource

Arguments

:: Task m a r 
=> Pool m a r

Pool

-> m (Integer, r)

Returns (number of task, task's result)

Read next result from the pool. This makes sense only if for pool which returns results.

resultsReader :: Task m a r => Pool m a r -> (Integer -> r -> IO b) -> IO ()Source

Read all results from pool and run given computation with each. Probably you will run this in the separate thread (using forkIO). This makes sense only if for pool which returns results.

waitFor :: Task m a r => Pool m a r -> m ()Source

Wait until all tasks will end

waitForIO :: Task m a r => Pool m a r -> IO ()Source

Wait until all tasks will end, in IO monad

waitForTasks :: Task m a r => Pool m a r -> [Integer] -> m ()Source

terminatePool :: Task m a r => Pool m a r -> m ()Source

Terminate all threads in the pool

terminatePoolIO :: Task m a r => Pool m a r -> IO ()Source

Terminate all threads in the pool, in IO monad