packages feed

spawn (empty) → 0.1

raw patch · 4 files changed

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

Dependencies added: base

Files

+ Control/Concurrent/Spawn.hs view
@@ -0,0 +1,32 @@+module Control.Concurrent.Spawn(+    -- * Spawn +    spawn++    -- * Spawn with @'try'@+  , Result+  , spawnTry) where++import Control.Concurrent+import Control.Exception++-- | Two ways a computation of type @'IO' a@ can end.+type Result a = Either SomeException a++-- | Spawn a concurrent computation.  Produces an action which+-- demands a @'Result'@.+spawnTry :: IO a -> IO (IO (Result a))+spawnTry m = do+  v <- newEmptyMVar+  -- block async exns, then unblock inside 'try' unless parent was blocked+  -- avoids dropping an exception+  b <- blocked+  _ <- block $ forkIO (try (if b then m else unblock m) >>= putMVar v)+  return (readMVar v)++-- | Spawn a concurrent computation.  Produces an action which+-- demands the result.  Any exception from the original computation+-- is re-thrown when and where the result is demanded.+spawn :: IO a -> IO (IO a)+spawn m = do+  r <- spawnTry m+  return (r >>= either throwIO return)
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) Keegan McAllister 2010++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.+2. 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.+3. Neither the name of the author nor the names of his contributors+   may 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 AUTHORS 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.hs view
@@ -0,0 +1,4 @@+#! /usr/bin/runhaskell++import Distribution.Simple+main = defaultMain
+ spawn.cabal view
@@ -0,0 +1,19 @@+name:                spawn+version:             0.1+license:             BSD3+license-file:        LICENSE+synopsis:            Tiny library for joinable computations / threads with results.+category:            Concurrency, Concurrent, Control+author:              Keegan McAllister <mcallister.keegan@gmail.com>+maintainer:          Keegan McAllister <mcallister.keegan@gmail.com>+build-type:          Simple+cabal-version:       >=1.2+description:+  Spawn a concurrent 'IO' computation and later demand its result.  Tiny API+  and implementation.++library+  exposed-modules:   Control.Concurrent.Spawn+  ghc-options:       -Wall+  build-depends:+      base >= 3 && < 5