Z-IO 0.6.3.0 → 0.6.4.0
raw patch · 3 files changed
+38/−16 lines, 3 filesnew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Z.IO.Process: initProcess' :: ProcessOptions -> Resource (Maybe UVStream, Maybe UVStream, Maybe UVStream, TVar ProcessState)
Files
- ChangeLog.md +5/−1
- Z-IO.cabal +1/−1
- Z/IO/Process.hsc +32/−14
ChangeLog.md view
@@ -1,8 +1,12 @@ # Revision history for Z-IO +## 0.6.4.0 -- 2020-02-20++* Add `initProcess'` to kill process while finish using the process resource by default.+ ## 0.6.3.0 -- 2020-02-20 -* Split `Z.IO.UV.FFI` to `Z.IO.UV.FFI` and `Z.IO.UV.FFI_Env`, to make the module buildable when memory is constrained. +* Split `Z.IO.UV.FFI` to `Z.IO.UV.FFI` and `Z.IO.UV.FFI_Env`, to make the module buildable when memory is constrained. * Make functions works on TTY in `Z.IO.StdStream` correctly ignore redirected streams. * Move `pathSeparator` to `pathSeparators`, now `pathSeparator` return the default path separator.
Z-IO.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: Z-IO-version: 0.6.3.0+version: 0.6.4.0 synopsis: Simple and high performance IO toolkit for Haskell description: Simple and high performance IO toolkit for Haskell, including
Z/IO/Process.hsc view
@@ -19,8 +19,9 @@ -} -module Z.IO.Process (- initProcess+module Z.IO.Process+ ( initProcess+ , initProcess' , readProcess , readProcessText , ProcessOptions(..)@@ -130,14 +131,16 @@ pattern SIGKILL = 9 -- on windows this is absent pattern SIGHUP = #const SIGHUP --- | Resource spawn processes.+-- | Resourced spawn processes. ----- Return a resource spawn processes, when initiated return the @(stdin, stdout, stderr, pstate)@ tuple,--- std streams are created when pass 'ProcessCreate' option, otherwise will be 'Nothing',--- @pstate@ will be updated to `ProcessExited` automatically when the process exits.+-- Return a resource spawn processes, when initiated return the+-- @(stdin, stdout, stderr, pstate)@ tuple, std streams are created when pass+-- 'ProcessCreate' option, otherwise will be 'Nothing', @pstate@ will be updated+-- to 'ProcessExited' automatically when the process exits. ----- A cleanup thread will be started when you finish using the process resource, to close any std stream--- created during spawn.+-- When you finish using the process resource, a cleanup action will be called+-- to wait process exit and close any std stream created during spawn. If you+-- also need to kill the process, see 'initProcess'' instead. -- -- @ -- initProcess defaultProcessOptions{@@ -148,12 +151,27 @@ -- waitProcessExit pstate -- wait for process exit on current thread. -- @ initProcess :: ProcessOptions -> Resource (Maybe UVStream, Maybe UVStream, Maybe UVStream, TVar ProcessState)-initProcess opt = initResource (spawn opt) $ \ (s0,s1,s2, pstate) -> void . forkIO $ do- _ <- waitProcessExit pstate- forM_ s0 closeUVStream- forM_ s1 closeUVStream- forM_ s2 closeUVStream+initProcess opt = initResource (spawn opt) $+ \ (s0,s1,s2, pstate) -> do+ _ <- waitProcessExit pstate+ forM_ s0 closeUVStream+ forM_ s1 closeUVStream+ forM_ s2 closeUVStream +-- | Resourced spawn processes.+--+-- The same as 'initProcess', but the clean action will try to send 'SIGTERM'+-- to the process first.+initProcess' :: ProcessOptions -> Resource (Maybe UVStream, Maybe UVStream, Maybe UVStream, TVar ProcessState)+initProcess' opt = initResource (spawn opt) $+ \ (s0, s1, s2, pstate) -> do+ m_pid <- getProcessPID pstate+ maybe (return ()) (flip killPID SIGTERM) m_pid+ _ <- waitProcessExit pstate+ forM_ s0 closeUVStream+ forM_ s1 closeUVStream+ forM_ s2 closeUVStream+ -- | Spawn a processe with given input. -- -- Child process's stdout and stderr output are collected, return with exit code.@@ -188,7 +206,7 @@ (out, err, e) <- readProcess opts (T.getUTF8Bytes inp) return (T.validate out, T.validate err, e) --- | Spawn a new thread+-- | Spawn a new process. -- -- Please manually close child process's std stream(if any) after process exits. spawn :: HasCallStack => ProcessOptions -> IO (Maybe UVStream, Maybe UVStream, Maybe UVStream, TVar ProcessState)