|
MissingH.Threads.Child | Portability | Haskell 2-pre | Stability | provisional | Maintainer | simons@cryp.to |
|
|
|
Description |
Control.Concurrent's forkIO is as low-level as it
gets: once you have forked an IO thread, it is
basically gone; all forkIO returns is (). If you
need more sophisticated control, you have to do it
yourself. This is what this library does.
|
|
Synopsis |
|
|
|
Documentation |
|
data Child a |
A Child is a cutely named data type which contains the
ThreadId of a forked computation and an MVar into
which the computation will put its return value once it
has terminated. Thus, you can wait for your children to
terminate by getting the value from that MVar. Another
property of children is that uncaught exceptions in them
will be propagated to your thread. So either you catch
them, or a failure in any however deeply nested child
will go right up to main.
| Constructors | |
|
|
mkChild :: Monoid a => ThreadId -> MVar a -> IO a -> IO () |
Wrap an IO computation so that (1) uncaught exceptions
are re-thrown to the given ThreadId, and that (2) it
will put the a it returns into the MVar. The value
has to be a Monoid because in case of (1) the wrapper
still needs some value to put into that MVar, so it
uses mempty. Popular monoids are () and [].
|
|
spawn :: Monoid a => IO a -> IO (Child a) |
Start an IO computation with the properties described
above.
|
|
wait :: Child a -> IO a |
Get the value returned by a "child process"; may be
mempty. But in case it is, you have just received an
asynchronous Exception anyway, so you have other things
to do. The function does not return until the child has
terminated. If your thread receives an exception while
it waits for the child, the child will be terminated
before wait returns. So once wait returns, the child
is guaranteed to be gone, one way or another.
|
|
send :: Child a -> Exception -> IO () |
A fancy wrapper for throwTo.
|
|
kill :: Child a -> IO () |
Wraps killThread.
|
|
par :: Monoid a => IO a -> IO a -> IO a |
Run both computations with spawn and return the value
of the child which terminates first. Both children are
guaranteed to be gone when par returns. Exceptions in
either child are propagated. So if either child fails,
par fails.
|
|
Produced by Haddock version 0.8 |