Skip to content

Commit

Permalink
Add IO.hClose primitve (#77)
Browse files Browse the repository at this point in the history
* add `IO.hClose` primitive

* add example of manually closing a handle
  • Loading branch information
austin-artificial authored Jan 10, 2025
1 parent d5da0d4 commit 4e3615a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/30-process-handlers.hell
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ main = do
Process.runProcess_ proc1
contents <- Text.readFile filePath
Text.putStrLn contents

-- 3. manually close the handle
Temp.withSystemTempFile "example-manual-close" \filePath handle -> do
Text.putStrLn $ Text.concat ["Created temp file ", filePath]
let proc = Process.setStdout (Process.useHandleOpen handle) $
Process.proc "echo" ["hello"]
Process.runProcess_ proc
-- manually close the handle so we can open the file to be read
IO.hClose handle
contents <- Text.readFile filePath
Text.putStrLn contents
1 change: 1 addition & 0 deletions src/Hell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ supportedLits =
("IO.NoBuffering", lit' IO.NoBuffering),
("IO.LineBuffering", lit' IO.LineBuffering),
("IO.BlockBuffering", lit' IO.BlockBuffering),
("IO.hClose", lit' IO.hClose),
-- Concurrent stuff
("Concurrent.threadDelay", lit' Concurrent.threadDelay),
-- Bool
Expand Down

0 comments on commit 4e3615a

Please sign in to comment.