@@ -1,26 +1,35 @@
1−import Strands
1+{-# LANGUAGE FlexibleContexts #-}
2+
3+import Control.Applicative ((<$>), (<*>), (<|>))
24import Control.Monad.IO.Class (liftIO)
5+import System.IO
6+import Strands
37
48main = do
5− logs <- waitLogged comp
9+ hSetBuffering stdout LineBuffering
10+ logs <- waitLogged_ comp
611
712 putStrLn $ "\nResuming with logs:"
8− logs1 <- waitLogged $ eachWithLog comp logs
13+ logs1 <- waitLogged_ $ eachWithLog comp logs
914
1015 putStrLn $ "\nResuming with logs:"
11− logs2 <- waitLogged $ eachWithLog comp logs1
16+ logs2 <- waitLogged_ $ eachWithLog comp logs1
1217
1318 putStrLn $ "\nLogs at the end must be empty:"
1419 putStrLn $ show logs2
1520
1621 putStrLn $ "\nRunning the last log again using wait:"
17− wait $ eachWithLog comp logs1
22+ wait_ $ eachWithLog comp logs1
1823
1924 where
25+
2026 comp = logged $ threads 5 $ do
2127 r <- logged $ each [1..3]
2228 logged $ liftIO $ print ("A",r)
2329 suspend
2430 logged $ liftIO $ print ("B",r)
31+ x <- logged $ (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
2532 suspend
26− liftIO $ print ("C",r)
33+ liftIO $ print ("C", r, x)
34+
35+ event n = async (do putStrLn ("event" ++ show n); return n :: IO Int)