packages feed

async (empty) → 1.0

raw patch · 4 files changed

+128/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ Control/Async.hs view
@@ -0,0 +1,65 @@+{- |+   Module      :  Control.Arrow.SP+   Copyright   :  (c) 2010 Peter Simons+   License     :  BSD3++   Maintainer  :  simons@cryp.to+   Stability   :  stable+   Portability :  portable+-}++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+  )+  where++import Control.Concurrent+import Control.Exception++type AsyncMVar a = MVar (Either SomeException a)++data Async a = Child ThreadId (AsyncMVar a)++forkAsync' :: IO a -> AsyncMVar a -> IO (Async a)+forkAsync' f mv = fmap (\p -> Child p mv) (forkIO f')+  where+    f' = block (try f >>= tryPutMVar mv >> return ())++forkAsync :: IO a -> IO (Async a)+forkAsync f = newEmptyMVar >>= forkAsync' f++throwToAsync :: Async a -> SomeException -> IO ()+throwToAsync (Child pid _) = throwTo pid++killAsync :: Async a -> IO ()+killAsync (Child pid _) = killThread pid++isReadyAsync :: Async a -> IO Bool+isReadyAsync (Child _ mv) = fmap not (isEmptyMVar mv)++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.++parIO :: IO a -> IO a -> IO a+parIO f g = do+  sync <- newEmptyMVar+  bracket+    (forkAsync' f sync)+    (killAsync)+    (\_ -> bracket+             (forkAsync' g sync)+             (killAsync)+             (waitForAsync))
+ LICENSE view
@@ -0,0 +1,30 @@+Redistribution and use in source and binary forms, with or+without modification, are permitted provided that the+following conditions are met:++  * Redistributions of source code must retain the above+    copyright notice, this list of conditions and the+    following disclaimer.++  * Redistributions in binary form must reproduce the above+    copyright notice, this list of conditions and the+    following disclaimer in the documentation and/or other+    materials provided with the distribution.++  * The names of its contributors may not be used to endorse+    or promote products derived from this software without+    specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,8 @@+#!/usr/bin/env runhaskell++> module Main (main) where+>+> import Distribution.Simple+>+> main :: IO ()+> main = defaultMain
+ async.cabal view
@@ -0,0 +1,25 @@+Name:                   async+Version:                1.0+Copyright:              (c) 2004-2010 Peter Simons+License:                BSD3+License-File:		LICENSE+Author:                 Peter Simons <simons@cryp.to>+Maintainer:             Peter Simons <simons@cryp.to>+Homepage:               http://gitorious.org/async/+Category:               Control+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++Source-Repository head+  Type:                 git+  Location:             git://gitorious.org/async/mainline.git++Library+  Build-Depends:        base >= 3 && < 5+  Exposed-Modules:      Control.Async+  Ghc-Options:          -Wall