packages feed

pms-infrastructure 0.0.1.0 → 0.0.2.0

raw patch · 3 files changed

+29/−12 lines, 3 files

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for pms-infrastructure +## 0.0.2.0 -- 2025-06-15++* Added finally to expect to ensure the lock is released.+ ## 0.0.1.0 -- 2025-05-31 -* First version. Released on an unsuspecting world.+* First version.
pms-infrastructure.cabal view
@@ -20,7 +20,7 @@ -- PVP summary:     +-+------- breaking API changes --                  | | +----- non-breaking API additions --                  | | | +--- code changes with no API change-version:            0.0.1.0+version:            0.0.2.0  -- A short (one-line) description of the package. synopsis:           pms-infrastructure
src/PMS/Infrastructure/DS/Core.hs view
@@ -319,19 +319,32 @@     errHdl :: E.SomeException -> IO ()     errHdl e = callback (ExitFailure 1) "" (show e) - -- | -- expect :: STM.TMVar () -> Pty -> [String] -> IO (Maybe String)-expect lock pms prompts = do-  m <- STM.atomically $ STM.tryTakeTMVar lock-  case m of-    Nothing -> return Nothing-    Just () -> do-      hPutStrLn stderr $ "[INFO] expect: " ++ show prompts-      output <- readUntilPrompt pms prompts-      STM.atomically $ STM.putTMVar lock ()-      return $ Just $ T.unpack $ TE.decodeUtf8 output+expect lock pty prompts = STM.atomically (STM.tryTakeTMVar lock) >>= \case+  Nothing -> do+    hPutStrLn stderr "[INFO] expect running. skip."+    return Nothing+  Just () -> flip E.catchAny exception $ flip E.finally finalize $ do+    hPutStrLn stderr $ "[INFO] expect: " ++ show prompts+    output <- readUntilPrompt pty prompts+    let result = T.unpack (TE.decodeUtf8 output)+    return (Just result)++  where+    -- |+    --+    exception :: E.SomeException -> IO (Maybe String)+    exception e = do+      hPutStrLn stderr $ "[ERROR] expect exception: " ++ show e+      return . Just . show $ e++    -- |+    --+    finalize :: IO ()+    finalize = STM.atomically $ STM.putTMVar lock ()+  -- | --