on b1ee90e help sign in
streamly/test/3-async.hs
24 lines 729 B history raw
1import Control.Concurrent (threadDelay, myThreadId)
2import Control.Monad.IO.Class (liftIO)
3import System.Random (randomIO)
4import System.IO
6import Asyncly
8main = do
9 hSetBuffering stdout LineBuffering
10 xs <- wait $ threads 4 $ do
11 liftIO $ hSetBuffering stdout LineBuffering
12 mainThread <- liftIO myThreadId
13 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
14 x <- liftIO (randomIO :: IO Int)
15 liftIO $ putStrLn $ show x
17 y <- liftIO (randomIO :: IO Int)
19 liftIO $ threadDelay 1000000
20 evThread <- liftIO myThreadId
21 liftIO $ putStrLn $ "Event thread: " ++ show evThread
22 liftIO $ putStrLn $ show y
23 return (x, y)
24 putStrLn $ show xs