[commit: packages/process] master: Expose withCreateProcess to users. (2398a4c)

git at git.haskell.org git at git.haskell.org
Wed Jul 19 21:16:51 UTC 2017


Repository : ssh://git@git.haskell.org/process

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/2398a4ca5b6fb999db670d00f07eb8d89c524d1b/process

>---------------------------------------------------------------

commit 2398a4ca5b6fb999db670d00f07eb8d89c524d1b
Author: Jon Coens <jcoens at jcoens-mbp1.dhcp.thefacebook.com>
Date:   Thu Aug 11 15:04:32 2016 +0100

    Expose withCreateProcess to users.
    
    The function was commented out and not used anywhere. I changed it to run cleanup on more than just exceptional cases.


>---------------------------------------------------------------

2398a4ca5b6fb999db670d00f07eb8d89c524d1b
 System/Process.hs | 21 ++++++++++-----------
 changelog.md      |  4 ++++
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/System/Process.hs b/System/Process.hs
index 37d442f..3b048b3 100644
--- a/System/Process.hs
+++ b/System/Process.hs
@@ -42,6 +42,7 @@ module System.Process (
     readProcess,
     readCreateProcessWithExitCode,
     readProcessWithExitCode,
+    withCreateProcess,
 
     -- ** Related utilities
     showCommandForUser,
@@ -196,29 +197,27 @@ createProcess cp = do
   maybeCloseStd _ = return ()
 
 {-
--- TODO: decide if we want to expose this to users
--- | A 'C.bracketOnError'-style resource handler for 'createProcess'.
+-- | A 'C.bracket'-style resource handler for 'createProcess'.
 --
--- In normal operation it adds nothing, you are still responsible for waiting
--- for (or forcing) process termination and closing any 'Handle's. It only does
--- automatic cleanup if there is an exception. If there is an exception in the
--- body then it ensures that the process gets terminated and any 'CreatePipe'
--- 'Handle's are closed. In particular this means that if the Haskell thread
--- is killed (e.g. 'killThread'), that the external process is also terminated.
+-- Does automatic cleanup when the action finishes. If there is an exception
+-- in the body then it ensures that the process gets terminated and any
+-- 'CreatePipe' 'Handle's are closed. In particular this means that if the
+-- Haskell thread is killed (e.g. 'killThread'), that the external process is
+-- also terminated.
 --
 -- e.g.
 --
 -- > withCreateProcess (proc cmd args) { ... }  $ \_ _ _ ph -> do
 -- >   ...
 --
+-}
 withCreateProcess
   :: CreateProcess
   -> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a)
   -> IO a
 withCreateProcess c action =
-    C.bracketOnError (createProcess c) cleanupProcess
-                     (\(m_in, m_out, m_err, ph) -> action m_in m_out m_err ph)
--}
+    C.bracket (createProcess c) cleanupProcess
+              (\(m_in, m_out, m_err, ph) -> action m_in m_out m_err ph)
 
 -- wrapper so we can get exceptions with the appropriate function name.
 withCreateProcess_
diff --git a/changelog.md b/changelog.md
index 7a220f7..fc27e26 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,9 @@
 # Changelog for [`process` package](http://hackage.haskell.org/package/process)
 
+## Unreleased
+
+  * New exposed `withCreateProcess`
+
 ## 1.4.2.0 *January 2016*
 
 * Added `createPipeFD` [#52](https://github.com/haskell/process/pull/52)



More information about the ghc-commits mailing list