From 4e3615a5ca58531d51264e02bd8a867a81d114ea Mon Sep 17 00:00:00 2001 From: austin-artificial <126663376+austin-artificial@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:59:29 +0000 Subject: [PATCH] Add `IO.hClose` primitve (#77) * add `IO.hClose` primitive * add example of manually closing a handle --- examples/30-process-handlers.hell | 11 +++++++++++ src/Hell.hs | 1 + 2 files changed, 12 insertions(+) diff --git a/examples/30-process-handlers.hell b/examples/30-process-handlers.hell index 9b28f63..2ea1661 100644 --- a/examples/30-process-handlers.hell +++ b/examples/30-process-handlers.hell @@ -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 diff --git a/src/Hell.hs b/src/Hell.hs index 1a7297c..54b99bf 100644 --- a/src/Hell.hs +++ b/src/Hell.hs @@ -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