buildbox-2.1.10.1: Rehackable components for writing buildbots and test harnesses.

Safe HaskellSafe
LanguageHaskell98

BuildBox.Control.Gang

Description

A gang consisting of a fixed number of threads that can run actions in parallel. Good for constructing parallel test frameworks.

Synopsis

Documentation

data Gang Source #

Abstract gang of threads.

data GangState Source #

Constructors

GangRunning

Gang is running and starting new actions.

GangPaused

Gang may be running already started actions, but no new ones are being started.

GangFlushing

Gang is waiting for currently running actions to finish, but not starting new ones.

GangFinished

Gang is finished, all the actions have completed.

GangKilled

Gang was killed, all the threads are dead (or dying).

forkGangActions Source #

Arguments

:: Int

Number of worker threads in the gang / maximum number of actions to execute concurrenty.

-> [IO ()]

Actions to run. They are started in-order, but may finish out-of-order depending on the run time of the individual action.

-> IO Gang 

Fork a new gang to run the given actions. This function returns immediately, with the gang executing in the background. Gang state starts as GangRunning then transitions to GangFinished. To block until all the actions are finished use joinGang.

joinGang :: Gang -> IO () Source #

Block until all actions have finished executing, or the gang is killed.

pauseGang :: Gang -> IO () Source #

Pause a gang. Actions that have already been started continue to run, but no more will be started until a resumeGang command is issued. Gang state changes to GangPaused.

resumeGang :: Gang -> IO () Source #

Resume a paused gang, which allows it to continue starting new actions. If the gang was paused it now changes to GangRunning, otherwise nothing happens.

flushGang :: Gang -> IO () Source #

Block until already started actions have completed, but don't start any more. Gang state changes to GangFlushing.

killGang :: Gang -> IO () Source #

Kill all the threads in a gang. Gang stage changes to GangKilled.

getGangState :: Gang -> IO GangState Source #

Get the state of a gang.

waitForGangState :: Gang -> GangState -> IO () Source #

Block until the gang is in the given state.