shellmate-0.3.4.1: Simple interface for shell scripting in Haskell.

Safe HaskellNone
LanguageHaskell2010

Control.Shell.Concurrent

Description

Concurrency for Shellmate programs.

Synopsis

Documentation

data Future a Source #

A future is a computation which is run in parallel with a program's main thread and which may at some later point finish and return a value.

Note that future computations are killed when their corresponding Future is garbage collected. This means that a future should *always* be awaited at some point or otherwise kept alive, to ensure that the computation finishes.

Note that all any code called in a future using unsafeLiftIO must refrain from using environment variables, standard input/output, relative paths and the current working directory, in order to avoid race conditions. Code within the Shell monad, code imported using liftIO and external processes spawned from within Shell is perfectly safe.

data ThreadId :: * #

A ThreadId is an abstract type representing a handle to a thread. ThreadId is an instance of Eq, Ord and Show, where the Ord instance implements an arbitrary total ordering over ThreadIds. The Show instance lets you convert an arbitrary-valued ThreadId to string form; showing a ThreadId value is occasionally useful when debugging or diagnosing the behaviour of a concurrent program.

Note: in GHC, if you have a ThreadId, you essentially have a pointer to the thread itself. This means the thread itself can't be garbage collected until you drop the ThreadId. This misfeature will hopefully be corrected at a later date.

forkIO :: Shell () -> Shell ThreadId Source #

Run a computation in a separate thread. If the thread throws an error, it will simply die; the error will not propagate to its parent thread.

killThread :: ThreadId -> Shell () Source #

Terminate a thread spawned by forkIO.

fork2 :: Shell () -> Shell (Handle, Handle, ThreadId) Source #

Run a computation in a separate thread, with its standard input and output provided by the first and second handles returned respectively. The handles are line buffered by default.

fork3 :: Shell () -> Shell (Handle, Handle, Handle, ThreadId) Source #

Like fork2, but adds a third handle for standard error.

future :: Shell a -> Shell (Future a) Source #

Create a future value.

await :: Future a -> Shell a Source #

Wait for a future value.

check :: Future a -> Shell (Maybe a) Source #

Check whether a future value has arrived or not.

parallel :: [Shell a] -> Shell [a] Source #

Perform the given computations in parallel. The race condition warning for Future when modifying environment variables or using relative paths still applies.

parallel_ :: [Shell a] -> Shell () Source #

Like parallel, but discards any return values.

chunks :: Int -> [a] -> [[a]] Source #

Break a list into chunks. This is quite useful for when performing *every* computation in parallel is too much. For instance, to download a list of files three at a time, one would do mapM_ (parallel_ downloadFile) (chunks 3 files).