on master help sign in
rename APIs
760a298Harendra Kumar
src/Strands.hs+3−2
@@ -11,9 +11,10 @@
11module Strands
11module Strands
12 ( wait
12 ( wait
13 , waitLogged
13 , waitLogged
14− , gather
14+ , wait_
15− , gatherLogged
15+ , waitLogged_
16 , async
16 , async
17+ , waitEvents
17 , each
18 , each
18 , sample
19 , sample
19 , threads
20 , threads
src/Strands/Threads.hs+10−12
@@ -12,12 +12,12 @@ module Strands.Threads
12 , threads
12 , threads
13
13
14 , wait
14 , wait
15− , gather
15+ , wait_
16
16
17 , logged
17 , logged
18 , suspend
18 , suspend
19 , waitLogged
19 , waitLogged
20− , gatherLogged
20+ , waitLogged_
21 , withLog
21 , withLog
22 , eachWithLog
22 , eachWithLog
23 )
23 )
@@ -539,18 +539,16 @@ gatherResult ref r = do
539
539
540-- | Run an 'AsyncT m' computation and collect the results generated by each
540-- | Run an 'AsyncT m' computation and collect the results generated by each
541-- thread of the computation in a list.
541-- thread of the computation in a list.
542−gather :: forall m a. (MonadIO m, MonadCatch m)
542+wait :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [a]
543− => AsyncT m a -> m [a]
543+wait m = do
544−gather m = do
545 resultsRef <- liftIO $ newIORef []
544 resultsRef <- liftIO $ newIORef []
546 waitAsync (gatherResult resultsRef) Nothing m
545 waitAsync (gatherResult resultsRef) Nothing m
547 liftIO $ readIORef resultsRef
546 liftIO $ readIORef resultsRef
548
547
549-- | Run an 'AsyncT m' computation, wait for it to finish and discard the
548-- | Run an 'AsyncT m' computation, wait for it to finish and discard the
550-- results.
549-- results.
551−wait :: forall m a. (MonadIO m, MonadCatch m)
550+wait_ :: (MonadIO m, MonadCatch m) => AsyncT m a -> m ()
552− => AsyncT m a -> m ()
553−wait m = waitAsync (const mzero) Nothing m
551+wait_ m = waitAsync (const mzero) Nothing m
554
552
555------------------------------------------------------------------------------
553------------------------------------------------------------------------------
556-- Logging
554-- Logging
@@ -636,8 +634,8 @@ eachWithLog m logs = each logs >>= withLog m
636
634
637-- | Run an 'AsyncT m' computation with logging enabled and collect the results
635-- | Run an 'AsyncT m' computation with logging enabled and collect the results
638-- or logs generated by each thread of the computation.
636-- or logs generated by each thread of the computation.
639−gatherLogged :: (MonadIO m, MonadCatch m) => AsyncT m a -> m ([a], [Log])
637+waitLogged :: (MonadIO m, MonadCatch m) => AsyncT m a -> m ([a], [Log])
640−gatherLogged m = do
638+waitLogged m = do
641 resultsRef <- liftIO $ newIORef []
639 resultsRef <- liftIO $ newIORef []
642 lref <- liftIO $ newIORef []
640 lref <- liftIO $ newIORef []
643 waitAsync (gatherResult resultsRef) (Just lref) m
641 waitAsync (gatherResult resultsRef) (Just lref) m
@@ -648,8 +646,8 @@ gatherLogged m = do
648-- | Run an 'AsyncT m' computation with logging enabled, wait for it to finish
646-- | Run an 'AsyncT m' computation with logging enabled, wait for it to finish
649-- and discard the results. If the computation suspends collect the logs to
647-- and discard the results. If the computation suspends collect the logs to
650-- replay later.
648-- replay later.
651−waitLogged :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [Log]
649+waitLogged_ :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [Log]
652−waitLogged m = do
650+waitLogged_ m = do
653 lref <- liftIO $ newIORef []
651 lref <- liftIO $ newIORef []
654 waitAsync (const mzero) (Just lref) m
652 waitAsync (const mzero) (Just lref) m
655 logs <- liftIO $ readIORef lref
653 logs <- liftIO $ readIORef lref
test/2-gather.hs+1−1
@@ -2,7 +2,7 @@ import Strands
2import Control.Monad.IO.Class (liftIO)
2import Control.Monad.IO.Class (liftIO)
3
3
4main = do
4main = do
5− xs <- gather $ do
5+ xs <- wait $ do
6 liftIO $ putStrLn "hello"
6 liftIO $ putStrLn "hello"
7 return 5
7 return 5
8 print xs
8 print xs
test/3-async.hs+1−1
@@ -7,7 +7,7 @@ import Strands
7
7
8main = do
8main = do
9 hSetBuffering stdout LineBuffering
9 hSetBuffering stdout LineBuffering
10− xs <- gather $ threads 4 $ do
10+ xs <- wait $ threads 4 $ do
11 liftIO $ hSetBuffering stdout LineBuffering
11 liftIO $ hSetBuffering stdout LineBuffering
12 mainThread <- liftIO myThreadId
12 mainThread <- liftIO myThreadId
13 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
13 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
test/3-sample.hs+1−1
@@ -5,7 +5,7 @@ import System.IO
5
5
6import Strands
6import Strands
7
7
8−main = wait $ threads 3 $ do
8+main = wait_ $ threads 3 $ do
9 liftIO $ hSetBuffering stdout LineBuffering
9 liftIO $ hSetBuffering stdout LineBuffering
10 mainThread <- liftIO myThreadId
10 mainThread <- liftIO myThreadId
11 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
11 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
test/alternative.hs+1−1
@@ -6,7 +6,7 @@ import Control.Applicative
6
6
7import Strands
7import Strands
8
8
9−main = wait $ threads 3 $ do
9+main = wait_ $ threads 3 $ do
10 liftIO $ hSetBuffering stdout LineBuffering
10 liftIO $ hSetBuffering stdout LineBuffering
11 mainThread <- liftIO myThreadId
11 mainThread <- liftIO myThreadId
12 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
12 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
test/applicative.hs+1−1
@@ -7,7 +7,7 @@ import Strands
7
7
8main = do
8main = do
9 hSetBuffering stdout LineBuffering
9 hSetBuffering stdout LineBuffering
10− xs <- gather $ threads 5 $ do
10+ xs <- wait $ threads 5 $ do
11 x <- (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
11 x <- (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
12 --x <- (,) <$> choose [1,2] <*> choose [3,4]
12 --x <- (,) <$> choose [1,2] <*> choose [3,4]
13 liftIO $ putStrLn $ show x
13 liftIO $ putStrLn $ show x