spawn-0.3: Tiny library for concurrent computations

Control.Concurrent.Spawn

Contents

Synopsis

Spawn

spawn :: IO a -> IO (IO a)Source

Spawn a concurrent computation. Produces an action which demands the result. Any exception from the original computation is re-thrown when and where the result is demanded.

Spawn with try

type Result a = Either SomeException aSource

Two ways a computation of type IO a can end.

spawnTry :: IO a -> IO (IO (Result a))Source

Spawn a concurrent computation. Produces an action which demands a Result.

Higher-level functions

parMapIO :: (a -> IO b) -> [a] -> IO [b]Source

Execute a separate thread of IO for each element of a list, and collect results.

The analogy to parMap is misleading. The concurrent execution of these actions is non-deterministic and can affect results. However, parMapIO is expected to be most useful for actions which do not interact.

parMapIO_ :: (a -> IO b) -> [a] -> IO ()Source

Execute a separate thread of IO for each element of a list.

Results are discarded, but the parMapIO_ action does not complete until all threads have finished.

(|*|) :: IO (a -> b) -> IO a -> IO bSource

A concurrent version of ap or (<*>) for IO.

Spawns a thread for the right-hand action, while executing the left-hand action in the current thread.

Limiting concurrency

pool :: Int -> IO (IO a -> IO a)Source

Given n, produces a function to wrap IO actions. No more than n wrapped actions will be in progress at one time.