packages feed

unsafe-promises 0.0 → 0.0.1

raw patch · 3 files changed

+17/−16 lines, 3 filessetup-changedPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Control/Concurrent/Promise/Unsafe.hs view
@@ -1,36 +1,36 @@--- |An experimental library for creating lazy promises that can be evaluated in +-- |An experimental library for lazy promises that can be evaluated in  -- pure code. -- -- Evaluation of a promise before its thread completes results in an  -- indefinite block. This is accomplished by the use of 'unsafeInterleaveIO'. -- Thus, care should be taken in using this library, since it couples the -- execution time of pure code with an arbitrary IO computation.--- Using "System.Timeout" from the timeout package can help to ensure that+-- Using System.Timeout from the timeout package can help to ensure that -- forcing a promise is always well-defined. ----- For safer implementations of promises, see "Control.Concurrent.Spawn" from --- the spawn package, and "Control.Concurrent.Future" from the future package. +-- For safer implementations of promises, see Control.Concurrent.Spawn from +-- the spawn package, and Control.Concurrent.Future from the future package.  module Control.Concurrent.Promise.Unsafe-       ( -- *Creating lazy promises+       ( -- *Creating promises          promise, tryPromise-         -- *Creating lists of lazy promises+         -- *Creating lists of promises        , promises, tryPromises        ) where -import Control.Concurrent.Thread-import Control.Concurrent.Chan-import Control.Exception-import System.IO.Unsafe+import Control.Concurrent.Thread (forkIO, Result, result)+import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)+import Control.Exception (catch)+import GHC.Conc (pseq)+import System.IO.Unsafe (unsafeInterleaveIO)  import Control.Monad import Control.Applicative-import Data.Function import Prelude hiding (catch)  safePromises :: [IO a] -> IO (Chan (Result a)) safePromises ios = do   c <- newChan-  forM ios $ +  forM_ ios $      \io ->  forkIO $ (writeChan c . Right =<< io)                      `catch` (writeChan c . Left)   return c@@ -56,7 +56,7 @@ promises :: [IO a] -> IO [a] promises ios = do   c <- safePromises ios-  forM ios $ \_ -> unsafeInterleaveIO (result =<< readChan c)+  fmap (scanl1 pseq) . forM ios $ \_ -> unsafeInterleaveIO (result =<< readChan c) {-# NOINLINE promises #-}  @@ -64,5 +64,6 @@ tryPromises :: [IO a] -> IO [Result a] tryPromises ios = do   c <- safePromises ios-  forM ios $ \_ -> unsafeInterleaveIO (readChan c)+  fmap (scanl1 pseq) . forM ios +    $ \_ -> unsafeInterleaveIO (readChan c) {-# NOINLINE tryPromises #-}
Setup.hs view
unsafe-promises.cabal view
@@ -1,5 +1,5 @@ Name: unsafe-promises-Version: 0.0+Version: 0.0.1 Cabal-Version: >= 1.6 License: BSD3 License-File: LICENSE@@ -10,7 +10,7 @@ Synopsis: Create pure futures using lazy IO. Build-type: Simple Description:-        An experimental library for creating lazy promises that can be+        An experimental library for creating promises that can be         evaluated in pure code.  source-repository this