Created
October 18, 2015 19:38
-
-
Save anonymous/b5da2b00ed2993594577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Monad | |
import Control.Concurrent.MVar | |
import qualified Data.ByteString.Char8 as BS8 | |
import Pipes.Cliff | |
import qualified Pipes.ByteString as PB | |
import System.Process | |
import System.IO | |
import System.Exit | |
toMVar mvar = forever $ do | |
liftIO $ putStrLn "await" | |
line <- await | |
liftIO $ BS8.putStrLn line | |
liftIO $ putMVar mvar line | |
client mvar = do | |
yield "LiNe 1\n" | |
line <- liftIO $ takeMVar mvar | |
yield "LiNe 2\n" | |
return ExitSuccess | |
mainCliff = do | |
withProcess (pipeInputOutput Pipes.Cliff.Inherit (procSpec "tr" ["[A-Z]", "[a-z]"])) $ | |
\(toTr, fromTr) -> do | |
mvar <- newEmptyMVar | |
toTrAsync <- conveyor $ client mvar >-> toTr | |
fromTrAsync <- conveyor $ fromTr >-> toMVar mvar | |
wait toTrAsync | |
wait fromTrAsync | |
main = do | |
(hin, hout,_,ph) <- runInteractiveProcess "tr" ["[A-Z],[a-z]"] Nothing Nothing | |
hSetBuffering hin NoBuffering | |
hSetBuffering hout NoBuffering | |
mvar <- newEmptyMVar | |
toTrAsync <- async $ runEffect $ client mvar >-> PB.toHandle hin | |
fromTrAsync <- async $ runEffect $ PB.fromHandle hout >-> toMVar mvar | |
wait toTrAsync | |
wait fromTrAsync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment