on b1ee90e help sign in
streamly/test/alternative.hs
30 lines 818 B history raw
1import Control.Concurrent (threadDelay, myThreadId)
2import Control.Monad.IO.Class (liftIO)
3import System.Random (randomIO)
4import System.IO
5import Control.Applicative
7import Asyncly
9main = wait_ $ threads 1 $ do
10 liftIO $ hSetBuffering stdout LineBuffering
11 mainThread <- liftIO myThreadId
12 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
14 eventA <|> eventB
16eventA = do
17 x <- liftIO (randomIO :: IO Int)
18 evThread <- liftIO myThreadId
19 liftIO $ putStrLn $ "X Event thread: " ++ show evThread
20 liftIO $ putStrLn $ "x = " ++ (show x)
21 return x
23eventB = do
24 y <- liftIO (randomIO :: IO Int)
26 -- liftIO $ threadDelay 10000000
27 evThread <- liftIO myThreadId
28 liftIO $ putStrLn $ "Y Event thread: " ++ show evThread
29 liftIO $ putStrLn $ "y = " ++ (show y)
30 return y