Distribution.Client.JobControl

cabal-install-3.12.1.0: The command-line interface for Cabal and Hackage.

Copyright | (c) Duncan Coutts 2012
License | BSD-like
Maintainer | cabal-devel@haskell.org
Stability | provisional
Portability | portable
Safe Haskell | None
Language | Haskell2010

Distribution.Client.JobControl

Description

A job control concurrency abstraction

Synopsis

- data JobControl (m :: Type -> Type) a
- newSerialJobControl :: IO (JobControl IO a)
- newParallelJobControl :: WithCallStack (Int -> IO (JobControl IO a))
- newSemaphoreJobControl :: WithCallStack (Verbosity -> 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 ()
- cleanupJobControl :: JobControl m a -> m ()
- jobControlSemaphore :: JobControl m a -> Maybe SemaphoreName
- 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 :: Type -> Type) a #

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) #

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)) #

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.

newSemaphoreJobControl :: WithCallStack (Verbosity -> Int -> IO (JobControl IO a)) #

Make a `JobControl` where the parallism is controlled by a semaphore.

This uses the GHC -jsem option to allow GHC to take additional semaphore slots if we are not using them all.

spawnJob :: JobControl m a -> m a -> m () #

Add a new job to the pool of jobs

collectJob :: JobControl m a -> m a #

Wait until one job is complete

remainingJobs :: JobControl m a -> m Bool #

Returns True if there are any outstanding jobs (ie spawned but yet to be collected)

cancelJobs :: JobControl m a -> m () #

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).

cleanupJobControl :: JobControl m a -> m () #

cleanup any resources created by the JobControl, intended to be used as the finaliser for `bracket`.

jobControlSemaphore :: JobControl m a -> Maybe SemaphoreName #

Name of the semaphore which can be used to control parallelism, if one is available for that job control type.

data JobLimit #

newJobLimit :: Int -> IO JobLimit #

withJobLimit :: JobLimit -> IO a -> IO a #

data Lock #

newLock :: IO Lock #

criticalSection :: Lock -> IO a -> IO a #