mirror of
https://github.com/ilyakooo0/streamly.git
synced 2024-10-06 21:27:35 +03:00
a74a0c0844
Streamly is a more appropriate name and conveys the core idea. Stream concurrently = streamly.
21 lines
590 B
Haskell
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
|