Safe Haskell | None |
---|---|
Language | Haskell2010 |
Concurrency for Shellmate programs.
Synopsis
- data Future a
- data ThreadId
- forkIO :: Shell () -> Shell ThreadId
- killThread :: ThreadId -> Shell ()
- fork2 :: Shell () -> Shell (Handle, Handle, ThreadId)
- fork3 :: Shell () -> Shell (Handle, Handle, Handle, ThreadId)
- future :: Shell a -> Shell (Future a)
- await :: Future a -> Shell a
- check :: Future a -> Shell (Maybe a)
- parallel :: [Shell a] -> Shell [a]
- parallel_ :: [Shell a] -> Shell ()
- chunks :: Int -> [a] -> [[a]]
Documentation
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
await
ed 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.
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
ThreadId
s. 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.
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.