streamly/examples/parallel-loops.hs
Harendra Kumar a74a0c0844 Rename to Streamly
Streamly is a more appropriate name and conveys the core idea. Stream
concurrently = streamly.
2017-11-20 18:03:13 +05:30

21 lines
590 B
Haskell

import Control.Applicative ((<|>))
import Control.Concurrent (myThreadId, threadDelay)
import Control.Monad.IO.Class (liftIO)
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
import System.Random (randomIO)
import Streamly
main = runStreamT $ do
liftIO $ hSetBuffering stdout LineBuffering
x <- loop "A" <|> loop "B"
liftIO $ myThreadId >>= putStr . show
>> putStr " "
>> print x
where
loop name = do
liftIO $ threadDelay 1000000
rnd <- liftIO (randomIO :: IO Int)
return (name, rnd) <|> loop name