Skip to content

Instantly share code, notes, and snippets.

Created October 18, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b5da2b00ed2993594577 to your computer and use it in GitHub Desktop.
Save anonymous/b5da2b00ed2993594577 to your computer and use it in GitHub Desktop.
{-# 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