Copyright | (c) Duncan Coutts 2012 |
---|---|
License | BSD-like |
Maintainer | cabal-devel@haskell.org |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A job control concurrency abstraction
Synopsis
- data JobControl m a
- newSerialJobControl :: IO (JobControl IO a)
- newParallelJobControl :: WithCallStack (Int -> IO (JobControl IO a))
- spawnJob :: JobControl m a -> m a -> m ()
- collectJob :: JobControl m a -> m a
- remainingJobs :: JobControl m a -> m Bool
- cancelJobs :: JobControl m a -> m ()
- data JobLimit
- newJobLimit :: Int -> IO JobLimit
- withJobLimit :: JobLimit -> IO a -> IO a
- data Lock
- newLock :: IO Lock
- criticalSection :: Lock -> IO a -> IO a
Documentation
data JobControl m a Source #
A simple concurrency abstraction. Jobs can be spawned and can complete in any order. This allows both serial and parallel implementations.
newSerialJobControl :: IO (JobControl IO a) Source #
Make a JobControl
that executes all jobs serially and in order.
It only executes jobs on demand when they are collected, not eagerly.
Cancelling will cancel all jobs that have not been collected yet.
newParallelJobControl :: WithCallStack (Int -> IO (JobControl IO a)) Source #
Make a JobControl
that eagerly executes jobs in parallel, with a given
maximum degree of parallelism.
Cancelling will cancel jobs that have not yet begun executing, but jobs that have already been executed or are currently executing cannot be cancelled.
spawnJob :: JobControl m a -> m a -> m () Source #
Add a new job to the pool of jobs
collectJob :: JobControl m a -> m a Source #
Wait until one job is complete
remainingJobs :: JobControl m a -> m Bool Source #
Returns True if there are any outstanding jobs (ie spawned but yet to be collected)
cancelJobs :: JobControl m a -> m () Source #
Try to cancel any outstanding but not-yet-started jobs.
Call remainingJobs
after this to find out if any jobs are left
(ie could not be cancelled).