Copyright | (c) 2010-2012 Bas van Dijk & Roel van Dijk |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com> |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Standard threads extended with the ability to wait for their return value.
This module exports equivalently named functions from Control.Concurrent
(and GHC.Conc
). Avoid ambiguities by importing this module qualified. May
we suggest:
import qualified Control.Concurrent.Thread as Thread ( ... )
The following is an example how to use this module:
import qualified Control.Concurrent.Thread as Thread (forkIO
,result
) main = do (tid, wait) <- Thread.forkIO
$ do x <- someExpensiveComputation return x doSomethingElse x <- Thread.result
=<<wait
doSomethingWithResult x
Synopsis
- forkIO :: IO a -> IO (ThreadId, IO (Result a))
- forkOS :: IO a -> IO (ThreadId, IO (Result a))
- forkOn :: Int -> IO a -> IO (ThreadId, IO (Result a))
- forkIOWithUnmask :: ((forall b. IO b -> IO b) -> IO a) -> IO (ThreadId, IO (Result a))
- forkOnWithUnmask :: Int -> ((forall b. IO b -> IO b) -> IO a) -> IO (ThreadId, IO (Result a))
- type Result a = Either SomeException a
- result :: Result a -> IO a
Forking threads
forkIO :: IO a -> IO (ThreadId, IO (Result a)) Source #
Like Control.Concurrent.
but returns
a computation that when executed blocks until the thread terminates
then returns the final value of the thread.forkIO
forkOS :: IO a -> IO (ThreadId, IO (Result a)) Source #
Like Control.Concurrent.
but returns
a computation that when executed blocks until the thread terminates
then returns the final value of the thread.forkOS
forkOn :: Int -> IO a -> IO (ThreadId, IO (Result a)) Source #
Like Control.Concurrent.
but returns
a computation that when executed blocks until the thread terminates
then returns the final value of the thread.forkOn
forkIOWithUnmask :: ((forall b. IO b -> IO b) -> IO a) -> IO (ThreadId, IO (Result a)) Source #
Like Control.Concurrent.
but returns
a computation that when executed blocks until the thread terminates
then returns the final value of the thread.forkIOWithUnmask
forkOnWithUnmask :: Int -> ((forall b. IO b -> IO b) -> IO a) -> IO (ThreadId, IO (Result a)) Source #
Like Control.Concurrent.
but returns
a computation that when executed blocks until the thread terminates
then returns the final value of the thread.forkOnWithUnmask
Results
type Result a = Either SomeException a Source #
A result of a thread is either some exception that was thrown in the thread and wasn't catched or the actual value that was returned by the thread.