promises 0 → 0.1
raw patch · 3 files changed
+20/−6 lines, 3 files
Files
- CHANGELOG.markdown +4/−0
- promises.cabal +1/−1
- src/Data/Promise.hs +15/−5
CHANGELOG.markdown view
@@ -1,3 +1,7 @@ ## 0 * Repository initialized++## 0.1++* Added `runLazyIO` and `runLazyIO_`.
promises.cabal view
@@ -1,6 +1,6 @@ name: promises category: Lazy, Concurrent-version: 0+version: 0.1 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE
src/Data/Promise.hs view
@@ -21,7 +21,11 @@ ----------------------------------------------------------------------------- module Data.Promise- ( Lazy, runLazy, runLazy_+ ( Lazy+ , runLazy+ , runLazy_+ , runLazyIO+ , runLazyIO_ , Promise(..) , promise, promise_ , (!=)@@ -178,15 +182,21 @@ -- * Running It All -------------------------------------------------------------------------------- --- | Run a lazy computation. The final answer is given in the form of a promise to be fulfilled.--- If the promises is unfulfilled then an user supplied default value will be returned.-runLazy :: (forall s. Promise s a -> Lazy s b) -> a -> a-runLazy f d = unsafePerformIO $ do+runLazyIO :: (forall s. Promise s a -> Lazy s b) -> a -> IO a+runLazyIO f d = do mv <- newEmptyMVar v <- newEmptyMVar let iv = Promise v (drive d mv v) putMVar mv (Just (getLazy (f iv) mv)) return $ demand iv++runLazyIO_ :: (forall s. Promise s a -> Lazy s b) -> IO a+runLazyIO_ k = runLazyIO k $ throw BrokenPromise++-- | Run a lazy computation. The final answer is given in the form of a promise to be fulfilled.+-- If the promises is unfulfilled then an user supplied default value will be returned.+runLazy :: (forall s. Promise s a -> Lazy s b) -> a -> a+runLazy f d = unsafePerformIO (runLazyIO f d) {-# NOINLINE runLazy #-} -- | Run a lazy computation. The final answer is given in the form of a promise to be fulfilled.