refactor
This commit is contained in:
parent
ac5cff3668
commit
6c0155efb7
4 changed files with 77 additions and 51 deletions
35
Utility/CoProcess.hs
Normal file
35
Utility/CoProcess.hs
Normal file
|
@ -0,0 +1,35 @@
|
|||
{- Interface for running a shell command as a coprocess,
|
||||
- sending it queries and getting back results.
|
||||
-
|
||||
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
module Utility.CoProcess (
|
||||
CoProcessHandle,
|
||||
start,
|
||||
stop,
|
||||
query
|
||||
) where
|
||||
|
||||
import System.Cmd.Utils
|
||||
|
||||
import Common
|
||||
|
||||
type CoProcessHandle = (PipeHandle, Handle, Handle)
|
||||
|
||||
start :: FilePath -> [String] -> IO CoProcessHandle
|
||||
start command params = hPipeBoth command params
|
||||
|
||||
stop :: CoProcessHandle -> IO ()
|
||||
stop (pid, from, to) = do
|
||||
hClose to
|
||||
hClose from
|
||||
forceSuccess pid
|
||||
|
||||
query :: CoProcessHandle -> (Handle -> IO a) -> (Handle -> IO b) -> IO b
|
||||
query (_, from, to) send receive = do
|
||||
_ <- send to
|
||||
hFlush to
|
||||
receive from
|
Loading…
Add table
Add a link
Reference in a new issue