@@ -1,26 +1,35 @@
1−import Strands
1+{-# LANGUAGE FlexibleContexts #-}
3+import Control.Applicative ((<$>), (<*>), (<|>))
2import Control.Monad.IO.Class (liftIO)
4import Control.Monad.IO.Class (liftIO)
9+ hSetBuffering stdout LineBuffering
5− logs <- waitLogged comp
10+ logs <- waitLogged_ comp
7 putStrLn $ "\nResuming with logs:"
12 putStrLn $ "\nResuming with logs:"
8− logs1 <- waitLogged $ eachWithLog comp logs
13+ logs1 <- waitLogged_ $ eachWithLog comp logs
10 putStrLn $ "\nResuming with logs:"
15 putStrLn $ "\nResuming with logs:"
11− logs2 <- waitLogged $ eachWithLog comp logs1
16+ logs2 <- waitLogged_ $ eachWithLog comp logs1
13 putStrLn $ "\nLogs at the end must be empty:"
18 putStrLn $ "\nLogs at the end must be empty:"
14 putStrLn $ show logs2
19 putStrLn $ show logs2
16 putStrLn $ "\nRunning the last log again using wait:"
21 putStrLn $ "\nRunning the last log again using wait:"
17− wait $ eachWithLog comp logs1
22+ wait_ $ eachWithLog comp logs1
20 comp = logged $ threads 5 $ do
26 comp = logged $ threads 5 $ do
21 r <- logged $ each [1..3]
27 r <- logged $ each [1..3]
22 logged $ liftIO $ print ("A",r)
28 logged $ liftIO $ print ("A",r)
24 logged $ liftIO $ print ("B",r)
30 logged $ liftIO $ print ("B",r)
31+ x <- logged $ (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
26− liftIO $ print ("C",r)
33+ liftIO $ print ("C", r, x)
35+ event n = async (do putStrLn ("event" ++ show n); return n :: IO Int)