packages feed

async 1.2 → 1.3

raw patch · 2 files changed

+37/−31 lines, 2 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

- Control.Async: throwToAsync :: Async a -> SomeException -> IO ()
+ Control.Async: throwToAsync :: Exception e => Async a -> e -> IO ()

Files

Control/Async.hs view
@@ -1,23 +1,21 @@ {- |-   Module      :  Control.Arrow.SP-   Copyright   :  (c) 2010 Peter Simons+   Module      :  Control.Async    License     :  BSD3-    Maintainer  :  simons@cryp.to    Stability   :  stable    Portability :  portable++   An implementation of IO computations that return their value asynchronously. -}  module Control.Async-  (-        Async                   -- Async a = Child ThreadId (AsyncMVar a)-  ,     forkAsync               -- :: IO a -> IO (Async a)-  ,     throwToAsync            -- :: Async a -> SomeException -> IO ()-  ,     killAsync               -- :: Async a -> IO ()-  ,     isReadyAsync            -- :: Async a -> IO Bool-  ,     waitForAsync            -- :: Async a -> IO a--  ,     parIO                   -- :: IO a -> IO a -> IO a+  ( Async+  , forkAsync+  , throwToAsync+  , killAsync+  , isReadyAsync+  , waitForAsync+  , parIO   )   where @@ -26,40 +24,48 @@  type AsyncMVar a = MVar (Either SomeException a) +-- | @Async a@ represents a value @a@ that is being computed+-- asynchronously, i.e. a value that is going to become available at+-- some point in the future. data Async a = Child ThreadId (AsyncMVar a)  forkAsync' :: IO a -> AsyncMVar a -> IO (Async a)-forkAsync' f mv = fmap (\p -> Child p mv) (block (forkIO f'))-  where-    f' = try (unblock f) >>= tryPutMVar mv >> return ()+forkAsync' f mv = fmap (`Child` mv) (mask $ \unmask -> forkIO (try (unmask f) >>= tryPutMVar mv >> return ())) +-- | Start an asynchronous computation. forkAsync :: IO a -> IO (Async a) forkAsync f = newEmptyMVar >>= forkAsync' f -throwToAsync :: Async a -> SomeException -> IO ()+-- | Throw an asynchronous exception to the thread that performs the+-- computation associated with this value.+throwToAsync :: Exception e => Async a -> e -> IO () throwToAsync (Child pid _) = throwTo pid +-- | Abort the asynchronous computation associated with this value. killAsync :: Async a -> IO () killAsync (Child pid _) = killThread pid +-- | Test whether the asynchronous value has become available. isReadyAsync :: Async a -> IO Bool isReadyAsync (Child _ mv) = fmap not (isEmptyMVar mv) +-- | Wait for the asynchronous value to become available, and retrieve+-- it. If the computation that generated the value has thrown an+-- exception, then that exception will be raised here. waitForAsync :: Async a -> IO a waitForAsync (Child _ sync) = fmap (either throw id) (readMVar sync) --- Run both computations in parallel and return the @a@ value--- of the computation that terminates first. An exception in--- either of the two computations aborts the entire parIO--- computation.+-- | Run both computations in parallel and return the @a@ value of the+-- computation that terminates first. An exception in either of the two+-- computations aborts the entire @parIO@ computation.  parIO :: IO a -> IO a -> IO a parIO f g = do   sync <- newEmptyMVar   bracket     (forkAsync' f sync)-    (killAsync)+    killAsync     (\_ -> bracket              (forkAsync' g sync)-             (killAsync)-             (waitForAsync))+             killAsync+             waitForAsync)
async.cabal view
@@ -1,19 +1,19 @@ Name:                   async-Version:                1.2-Copyright:              (c) 2004-2010 Peter Simons+Version:                1.3+Copyright:              (c) 2004-2011 Peter Simons License:                BSD3-License-File:		LICENSE+License-File:           LICENSE Author:                 Peter Simons <simons@cryp.to> Maintainer:             Peter Simons <simons@cryp.to> Homepage:               http://gitorious.org/async/-Category:               Control+Category:               Control, Concurrency, Parallelism Synopsis:               Asynchronous Computations--Description:		An implementation of IO computations that return their-			value asynchronously. Cabal-Version:          >= 1.6 Build-Type:             Simple-Tested-With:            GHC == 6.12.1+Tested-With:            GHC == 6.12.3, GHC == 7.0.4, GHC == 7.2.1+Description:+  An implementation of IO computations that return their value+  asynchronously.  Source-Repository head   Type:                 git