on master help sign in
Enable threads API and tests
commit4f3775d51f7eaeff9ecdedf7d461b23a097e0e7a authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 9 Aug 2017, 17:44 (9 years ago) parent17b30ba
3 files changed+20−24
src/Asyncly.hs+1−4 src/Asyncly/RunAsync.hs+6−7 test/Main.hs+13−13
src/Asyncly.hs+1−4
@@ -122,20 +122,17 @@
122122module Asyncly
123123 ( AsynclyT
124124 , MonadAsync
125− , AsyncT
126125
127126 -- * Run
128127 , runAsyncly
129128 , toList
130−-- , threads
129+ , threads
131130 , each
132131
133132{-
134133 -- * Fork and Gather
135134 --, async
136135 --, makeAsync
137− , each
138− --, gather
139136
140137 -- * Record and Play
141138 --, waitRecord
src/Asyncly/RunAsync.hs+6−7
@@ -14,14 +14,12 @@
1414-- Portability : GHC
1515--
1616module Asyncly.RunAsync
17− ( runAsyncly
17+ ( AsynclyT
18+ , runAsyncly
1819 , toList
19− , AsynclyT
20−-- , threads
2120 , each
21+ , threads
2222 {-
23− , gather
24−
2523 , waitRecord_
2624 , waitRecord
2725 , playRecordings
@@ -122,8 +120,9 @@ each xs = foldr (<|>) empty $ map return xs
122120-- | Runs a computation under a given thread limit. A limit of 0 means all new
123121-- tasks start synchronously in the current thread unless overridden by
124122-- 'async'.
125−-- threads :: MonadAsync m => Int -> AsynclyT m a -> AsynclyT m a
126−-- threads n action = AsynclyT $ AsyncT $ threadCtl n (runAsyncT $ runAsynclyT action)
123+threads :: MonadAsync m => Int -> AsynclyT m a -> AsynclyT m a
124+threads n action = AsynclyT $ AsyncT $ \stp yld ->
125+ threadCtl n ((runAsyncT $ runAsynclyT action) stp yld)
127126
128127{-
129128------------------------------------------------------------------------------
test/Main.hs+13−13
@@ -11,20 +11,20 @@ default (Int)
1111
1212main :: IO ()
1313main = hspec $ do
14− it "simple wait_" $
15− wait_ (return 0) `shouldReturn` ()
16− it "simple wait_ with IO" $
17− wait_ (liftIO $ putStrLn "hello") `shouldReturn` ()
18− it "Captures a return value using wait" $
19− wait (return 0) `shouldReturn` ([0] :: [Int])
20− it "simple wait_ and 'then' with IO" $
21− wait_ (liftIO (putStrLn "hello") >> liftIO (putStrLn "world")) `shouldReturn` ()
22− it "Then and wait" $
23− wait (return 1 >> return 2) `shouldReturn` ([2] :: [Int])
24− it "Bind and wait" $
25− wait (do x <- return 1; y <- return 2; return (x + y)) `shouldReturn` ([3] :: [Int])
14+ it "simple runAsyncly" $
15+ runAsyncly (return 0) `shouldReturn` ()
16+ it "simple runAsyncly with IO" $
17+ runAsyncly (liftIO $ putStrLn "hello") `shouldReturn` ()
18+ it "Captures a return value using toList" $
19+ toList (return 0) `shouldReturn` ([0] :: [Int])
20+ it "simple runAsyncly and 'then' with IO" $
21+ runAsyncly (liftIO (putStrLn "hello") >> liftIO (putStrLn "world")) `shouldReturn` ()
22+ it "Then and toList" $
23+ toList (return 1 >> return 2) `shouldReturn` ([2] :: [Int])
24+ it "Bind and toList" $
25+ toList (do x <- return 1; y <- return 2; return (x + y)) `shouldReturn` ([3] :: [Int])
2626 it "Alternative composition of sync tasks" $
27− ((wait $ threads 0 $ (return 0 <|> return 1)) >>= return . sort) `shouldReturn` ([0, 1] :: [Int])
27+ ((toList $ threads 0 $ (return 0 <|> return 1)) >>= return . sort) `shouldReturn` ([0, 1] :: [Int])
2828 {-
2929 it "Alternative composition of async and sync tasks" $
3030 ((wait (threads 0 ((async (return 0) <|> return 1)))) >>= return . sort)