mirror of
https://github.com/ilyakooo0/streamly.git
synced 2024-10-06 13:17:10 +03:00
9c85811905
and some other related refactoring changes.
27 lines
821 B
Haskell
27 lines
821 B
Haskell
import Control.Concurrent (myThreadId, threadDelay)
|
|
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
|
|
import System.Random (randomIO)
|
|
import Streamly
|
|
import qualified Streamly.Prelude as S
|
|
|
|
main = do
|
|
hSetBuffering stdout LineBuffering
|
|
runStream $ do
|
|
x <- S.take 10 $ loop "A" `parallel` loop "B"
|
|
S.yieldM $ myThreadId >>= putStr . show
|
|
>> putStr " got "
|
|
>> print x
|
|
|
|
where
|
|
|
|
-- we can just use
|
|
-- parallely $ cycle1 $ yieldM (...)
|
|
loop :: String -> Serial (String, Int)
|
|
loop name = do
|
|
S.yieldM $ threadDelay 1000000
|
|
rnd <- S.yieldM (randomIO :: IO Int)
|
|
S.yieldM $ myThreadId >>= putStr . show
|
|
>> putStr " yielding "
|
|
>> print rnd
|
|
return (name, rnd) `parallel` loop name
|