@@ -3,7 +3,7 @@ module Main (main) where
3import Test.Hspec
3import Test.Hspec
5import Control.Applicative ((<|>))
5import Control.Applicative ((<|>))
6−--import Control.Monad.IO.Class (liftIO)
6+import Control.Monad.IO.Class (liftIO)
7import Asyncly
7import Asyncly
8import Data.List (sort)
8import Data.List (sort)
@@ -34,3 +34,30 @@ main = hspec $ do
34 it "Nested async tasks with Alternative" $
34 it "Nested async tasks with Alternative" $
35 (wait (async (async $ return 0) <|> return 1) >>= return . sort)
35 (wait (async (async $ return 0) <|> return 1) >>= return . sort)
36 `shouldReturn` ([0,1] :: [Int])
36 `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])
44+generalExample :: AsyncT IO Int
47+ liftIO $ print "hello"
48+ x <- async (return 1)
49+ y <- async (return 2)
51+ x1 <- async (return 1) <|> async (return 2)
53+ liftIO $ print "hello"
54+ y1 <- (return 1) <|> async (return 2)
56+ x11 <- async (return 1) <|> (return 2)
57+ y11 <- async (return 1) <|> async (return 2)
58+ z11 <- async (return 1) <|> (return 2)
60+ liftIO $ print "hello"
62+ return (x1 + y1 + z1)