Portability | POSIX |
---|---|
Stability | experimental |
Maintainer | bastianholst@gmx.de |
Safe Haskell | None |
High level bag of tasks interface based on Control.Concurrent.Bag.Basic. Tasks can only return results and add new tasks as intended and it is not possible to add new tasks from the outside or from the action processing the results.
- module Control.Concurrent.Bag.Task
- newTaskBag :: BufferType -> Maybe (SplitFunction r) -> [TaskIO r (Maybe r)] -> IO [r]
- newEvalBag :: BufferType -> Maybe (SplitFunction r) -> [r] -> IO [r]
- type SplitFunction r = TaskBufferSTM (IO (Maybe r)) -> TaskBufferSTM (IO (Maybe r)) -> STM (IO (Maybe r))
- takeFirst :: SplitFunction r
- newInterruptingBag :: BufferType -> Maybe (SplitFunction r) -> [Interruptible r] -> IO [r]
- newInterruptibleBag :: BufferType -> Maybe (SplitFunction r) -> [Interruptible r] -> IO [r]
- data BufferType
Documentation
module Control.Concurrent.Bag.Task
:: BufferType | buffer type |
-> Maybe (SplitFunction r) | Possible split function If the function is given, we will create a bag with one buffer per worker reducing the communication between the workers. |
-> [TaskIO r (Maybe r)] | list of initial tasks |
-> IO [r] | lazy result list |
Build and start a new task bag.
The returned list is not evaluated yet, but will be evaluated on demand later. Already computed results will be kept in a buffer until the result list is evaluated. If the result list gets garbage collected, the bag of tasks will be stopped automatically.
:: BufferType | buffer type |
-> Maybe (SplitFunction r) | Possible split function If the function is given, we will create a bag with one buffer per worker reducing the communication between the workers. |
-> [r] | given expressions to evaluate |
-> IO [r] | lazy result list |
Like newTaskBag
, but it takes a list of expressions that will be
evaluated to weak head normal form using seq
.
__WARNING__: This does not evaluate to normal form, but only to weak head normal form.
type SplitFunction r = TaskBufferSTM (IO (Maybe r)) -> TaskBufferSTM (IO (Maybe r)) -> STM (IO (Maybe r))Source
Split functions are used to split the contents of the source buffer into two parts. One part is left in this buffer or put back later; the other part is written into the sink buffer. One element of this part is returned in the STM monad. This is why the source buffer should always have at least one item available. If it has not, the action will suspend.
takeFirst :: SplitFunction rSource
Just take the first item from the source buffer.
:: BufferType | buffer type |
-> Maybe (SplitFunction r) | Possible split function If the function is given, we will create a bag with one buffer per worker reducing the communication between the workers. |
-> [Interruptible r] | list of initial tasks |
-> IO [r] | lazy result list |
Similar to newInterruptibleBag
, but interrupts the tasks in certain intervals.
Using a TChan
as buffer, this ensures
completeness: all tasks that have a result will get their time to evaluate
it. Note, that calculations, that do no memory allocation, cannot be
interrupted.
:: BufferType | buffer type |
-> Maybe (SplitFunction r) | Possible split function If the function is given, we will create a bag with one buffer per worker reducing the communication between the workers. |
-> [Interruptible r] | list of initial tasks |
-> IO [r] | lazy result list |
Similar to newTaskBag
, but taking a list of Interruptible
instead of
tasks.