on master help sign in
rename APIs
commit760a29859802dc76b595f2b57258522805639c3c authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 29 Jun 2017, 05:21 (9 years ago) parentf455a06
7 files changed+18−19
src/Strands.hs+3−2 src/Strands/Threads.hs+10−12 test/2-gather.hs+1−1 test/3-async.hs+1−1 test/3-sample.hs+1−1 test/alternative.hs+1−1 test/applicative.hs+1−1
src/Strands.hs+3−2
@@ -11,9 +11,10 @@
1111module Strands
1212 ( wait
1313 , waitLogged
14− , gather
15− , gatherLogged
14+ , wait_
15+ , waitLogged_
1616 , async
17+ , waitEvents
1718 , each
1819 , sample
1920 , threads
src/Strands/Threads.hs+10−12
@@ -12,12 +12,12 @@ module Strands.Threads
1212 , threads
1313
1414 , wait
15− , gather
15+ , wait_
1616
1717 , logged
1818 , suspend
1919 , waitLogged
20− , gatherLogged
20+ , waitLogged_
2121 , withLog
2222 , eachWithLog
2323 )
@@ -539,18 +539,16 @@ gatherResult ref r = do
539539
540540-- | Run an 'AsyncT m' computation and collect the results generated by each
541541-- thread of the computation in a list.
542−gather :: forall m a. (MonadIO m, MonadCatch m)
543− => AsyncT m a -> m [a]
544−gather m = do
542+wait :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [a]
543+wait m = do
545544 resultsRef <- liftIO $ newIORef []
546545 waitAsync (gatherResult resultsRef) Nothing m
547546 liftIO $ readIORef resultsRef
548547
549548-- | Run an 'AsyncT m' computation, wait for it to finish and discard the
550549-- results.
551−wait :: forall m a. (MonadIO m, MonadCatch m)
552− => AsyncT m a -> m ()
553−wait m = waitAsync (const mzero) Nothing m
550+wait_ :: (MonadIO m, MonadCatch m) => AsyncT m a -> m ()
551+wait_ m = waitAsync (const mzero) Nothing m
554552
555553------------------------------------------------------------------------------
556554-- Logging
@@ -636,8 +634,8 @@ eachWithLog m logs = each logs >>= withLog m
636634
637635-- | Run an 'AsyncT m' computation with logging enabled and collect the results
638636-- or logs generated by each thread of the computation.
639−gatherLogged :: (MonadIO m, MonadCatch m) => AsyncT m a -> m ([a], [Log])
640−gatherLogged m = do
637+waitLogged :: (MonadIO m, MonadCatch m) => AsyncT m a -> m ([a], [Log])
638+waitLogged m = do
641639 resultsRef <- liftIO $ newIORef []
642640 lref <- liftIO $ newIORef []
643641 waitAsync (gatherResult resultsRef) (Just lref) m
@@ -648,8 +646,8 @@ gatherLogged m = do
648646-- | Run an 'AsyncT m' computation with logging enabled, wait for it to finish
649647-- and discard the results. If the computation suspends collect the logs to
650648-- replay later.
651−waitLogged :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [Log]
652−waitLogged m = do
649+waitLogged_ :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [Log]
650+waitLogged_ m = do
653651 lref <- liftIO $ newIORef []
654652 waitAsync (const mzero) (Just lref) m
655653 logs <- liftIO $ readIORef lref
test/2-gather.hs+1−1
@@ -2,7 +2,7 @@ import Strands
22import Control.Monad.IO.Class (liftIO)
33
44main = do
5− xs <- gather $ do
5+ xs <- wait $ do
66 liftIO $ putStrLn "hello"
77 return 5
88 print xs
test/3-async.hs+1−1
@@ -7,7 +7,7 @@ import Strands
77
88main = do
99 hSetBuffering stdout LineBuffering
10− xs <- gather $ threads 4 $ do
10+ xs <- wait $ threads 4 $ do
1111 liftIO $ hSetBuffering stdout LineBuffering
1212 mainThread <- liftIO myThreadId
1313 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
test/3-sample.hs+1−1
@@ -5,7 +5,7 @@ import System.IO
55
66import Strands
77
8−main = wait $ threads 3 $ do
8+main = wait_ $ threads 3 $ do
99 liftIO $ hSetBuffering stdout LineBuffering
1010 mainThread <- liftIO myThreadId
1111 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
test/alternative.hs+1−1
@@ -6,7 +6,7 @@ import Control.Applicative
66
77import Strands
88
9−main = wait $ threads 3 $ do
9+main = wait_ $ threads 3 $ do
1010 liftIO $ hSetBuffering stdout LineBuffering
1111 mainThread <- liftIO myThreadId
1212 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
test/applicative.hs+1−1
@@ -7,7 +7,7 @@ import Strands
77
88main = do
99 hSetBuffering stdout LineBuffering
10− xs <- gather $ threads 5 $ do
10+ xs <- wait $ threads 5 $ do
1111 x <- (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
1212 --x <- (,) <$> choose [1,2] <*> choose [3,4]
1313 liftIO $ putStrLn $ show x