mirror of
https://github.com/composewell/streamly.git
synced 2024-11-11 00:53:46 +03:00
35 lines
1.0 KiB
Haskell
35 lines
1.0 KiB
Haskell
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
import Control.Applicative ((<$>), (<*>), (<|>))
|
|
import Control.Monad.IO.Class (liftIO)
|
|
import System.IO
|
|
import Asyncly
|
|
import Control.Monad.Trans.Recorder (pause, record)
|
|
|
|
main = do
|
|
hSetBuffering stdout LineBuffering
|
|
logs <- runAsynclyRecorded comp
|
|
|
|
putStrLn $ "\nResuming with logs:"
|
|
logs1 <- runAsynclyRecorded $ playRecordings comp logs
|
|
|
|
putStrLn $ "\nResuming with logs:"
|
|
logs2 <- runAsynclyRecorded $ playRecordings comp logs1
|
|
|
|
putStrLn $ "\nLogs at the end must be empty:"
|
|
putStrLn $ show logs2
|
|
|
|
where
|
|
|
|
comp = record $ threads 5 $ do
|
|
r <- record $ each [1..3]
|
|
record $ liftIO $ print ("A",r)
|
|
record pause
|
|
record $ liftIO $ print ("B",r)
|
|
x <- record $ (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
|
|
record pause
|
|
liftIO $ print ("C", r, x)
|
|
|
|
-- event n = async $ liftIO $ (do putStrLn ("event" ++ show n); return n :: IO Int)
|
|
event n = liftIO $ (do putStrLn ("event" ++ show n); return n :: IO Int)
|