@@ -3,7 +3,7 @@ module Main (main) where
33import Test.Hspec
44
55import Control.Applicative ((<|>))
6−--import Control.Monad.IO.Class (liftIO)
6+import Control.Monad.IO.Class (liftIO)
77import Asyncly
88import Data.List (sort)
99
@@ -34,3 +34,30 @@ main = hspec $ do
3434 it "Nested async tasks with Alternative" $
3535 (wait (async (async $ return 0) <|> return 1) >>= return . sort)
3636 `shouldReturn` ([0,1] :: [Int])
37+ it "General example" $
38+ (wait generalExample >>= return . sort)
39+ `shouldReturn` ([7,7,8,8,8,8,8,8,9,9,9,9,9,9,10,10] :: [Int])
40+ it "General example synchronous" $
41+ (wait (threads 0 generalExample) >>= return . sort)
42+ `shouldReturn` ([7,7,8,8,8,8,8,8,9,9,9,9,9,9,10,10] :: [Int])
43+
44+generalExample :: AsyncT IO Int
45+generalExample = do
46+ liftIO $ return ()
47+ liftIO $ print "hello"
48+ x <- async (return 1)
49+ y <- async (return 2)
50+ z <- do
51+ x1 <- async (return 1) <|> async (return 2)
52+ liftIO $ return ()
53+ liftIO $ print "hello"
54+ y1 <- (return 1) <|> async (return 2)
55+ z1 <- do
56+ x11 <- async (return 1) <|> (return 2)
57+ y11 <- async (return 1) <|> async (return 2)
58+ z11 <- async (return 1) <|> (return 2)
59+ liftIO $ return ()
60+ liftIO $ print "hello"
61+ return (x11 + y11)
62+ return (x1 + y1 + z1)
63+ return (x + y + z)