Skip to content

Commit

Permalink
add Process.useHandleOpen primitive (#76)
Browse files Browse the repository at this point in the history
* add `Process.useHandleOpen` primitive

* update process handlers example
  • Loading branch information
austin-artificial authored Jan 9, 2025
1 parent cc10780 commit d5da0d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions examples/30-process-handlers.hell
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
main = do
-- 1. close the handle after the process
Temp.withSystemTempFile "example" \filePath handle -> do
Text.putStrLn $ Text.concat ["Created temp file ", filePath]
let proc = Process.setStdout (Process.useHandleClose handle) $
Process.proc "ls" ["-al"]
Process.runProcess_ proc
contents <- Text.readFile filePath
Text.putStrLn contents

-- 2. keep the handle open after the process
Temp.withSystemTempFile "example-open" \filePath handle -> do
Text.putStrLn $ Text.concat ["Created temp file ", filePath]
let proc0 = Process.setStdout (Process.useHandleOpen handle) $
Process.proc "echo" ["hello"]
-- second time around we we make sure to close the handle
-- so we can then read the file later
let proc1 = Process.setStdout (Process.useHandleClose handle) $
Process.proc "echo" ["world"]
Process.runProcess_ proc0
Process.runProcess_ proc1
contents <- Text.readFile filePath
Text.putStrLn contents
3 changes: 2 additions & 1 deletion src/Hell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,8 @@ polyLits =
"Process.runProcess" runProcess :: forall a b c. ProcessConfig a b c -> IO ExitCode
"Process.runProcess_" runProcess_ :: forall a b c. ProcessConfig a b c -> IO ()
"Process.setStdout" setStdout :: forall stdin stdout stdout' stderr. StreamSpec 'STOutput stdout' -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout' stderr
"Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
"Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
"Process.useHandleOpen" useHandleOpen :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
|]
)

Expand Down

0 comments on commit d5da0d4

Please sign in to comment.