ENH use better types for wait

This commit is contained in:
Nathan Dwarshuis 2022-12-31 16:18:51 -05:00
parent c13de68d4f
commit 7e9d7d6d4b
2 changed files with 4 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import RIO
import RIO.Process
import qualified RIO.Text as T
import System.Environment
import System.Process (Pid)
import Text.XML.Light
import XMonad.Internal.Concurrent.VirtualBox
import XMonad.Internal.IO
@ -54,7 +55,7 @@ vmLaunch i = do
"Failed to start VM: "
<> displayBytesUtf8 (encodeUtf8 i)
vmPID :: T.Text -> RIO SimpleApp (Maybe Int)
vmPID :: T.Text -> RIO SimpleApp (Maybe Pid)
vmPID vid = do
(rc, out) <- proc "pgrep" ["-f", "VirtualBoxVM.*" ++ T.unpack vid] readProcessStdout
return $ case rc of

View File

@ -31,6 +31,7 @@ import RIO.Directory
import RIO.FilePath
import qualified RIO.Text as T
import System.IO.Error
import System.Process
--------------------------------------------------------------------------------
-- read
@ -161,7 +162,7 @@ getPermissionsSafe f = do
-- | Block until a PID has exited.
-- Use this to control flow based on a process that was not explicitly started
-- by the Haskell runtime itself, and thus has no data structures to query.
waitUntilExit :: (MonadIO m, Show t, Num t) => t -> m ()
waitUntilExit :: (MonadIO m) => Pid -> m ()
waitUntilExit pid = do
res <- doesDirectoryExist $ "/proc" </> show pid
when res $ do