gang-of-threads-3.2.1: Non-deterministic parallelism with bags

PortabilityPOSIX
Stabilityexperimental
Maintainerbastianholst@gmx.de
Safe HaskellSafe-Inferred

Control.Concurrent.Bag.Task

Description

Task implementations Interruptible and TaskIO. These can be use by some of the bag of tasks interfaces such as Control.Concurrent.Bag.Implicit and Control.Concurrent.Bag.ImplicitConcurrent.

Synopsis

Documentation

data TaskIO r a Source

A monad in which tasks can be specified. Task is instancing MonadIO and it therefore has the function liftIO to perform arbitrary IO actions. Tasks may or may not return a value. If it returns a value, this value is written back as a result. Additionally there is a function addTask to add new tasks to the bag. The parameter r is the result type of the corresponding bag. In contrast to Interruptible the evaluation order is simililar to that of the IO monad and tasks added by addTaskIO are added immediately.

Instances

runTaskIOSource

Arguments

:: TaskIO r (Maybe r)

The task to be run

-> AddTask r

Function to add a new task

-> WriteResult r

Function to write back a result

-> IO (Maybe r)

Returns a value if the task did

Run a task as an IO action.

addTaskIO :: TaskIO r (Maybe r) -> TaskIO r ()Source

Add a task to the bag of tasks from another task. The task will be added immediately.

writeResult :: r -> TaskIO r ()Source

Write back a result from a task.

data Interruptible r Source

A type to specify interruptible tasks. Interruptible tasks are tasks that can be interrupted and resumed later. Basically this means that the evaluating thread may be killed in between. Side-effects in this code are not allowed, and therefore all interrupted tasks have to be pure functional in contrast to TaskIO tasks. Otherwise this is similar to TaskIO.

runInterrupted :: Interruptible r -> TaskIO r (Maybe r)Source

Run the given interruptible task with interruptions.

Note: When using this function, it may be possible that some tasks are never completed, because the time to produce an intermediate result is longer than the interruption frequency.

runInterruptible :: Interruptible r -> TaskIO r (Maybe r)Source

Run the given interruptible task.

Run with this function, the task will not be interrupted.

type WriteResult r = r -> IO ()Source

Function to write back a result.

type AddTask r = IO (Maybe r) -> IO ()Source

Function to add a task to the bag of tasks.