aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Control/Monad/Extended.hs14
-rw-r--r--src/Reaktor/Plugins/System.hs9
2 files changed, 16 insertions, 7 deletions
diff --git a/src/Control/Monad/Extended.hs b/src/Control/Monad/Extended.hs
new file mode 100644
index 0000000..d91b12c
--- /dev/null
+++ b/src/Control/Monad/Extended.hs
@@ -0,0 +1,14 @@
+module Control.Monad.Extended
+ ( module Control.Monad
+ , unlessM_
+ , untilM_
+ ) where
+
+import Control.Monad
+
+
+unlessM_ :: Monad m => m Bool -> m () -> m ()
+unlessM_ p f = p >>= flip unless f
+
+untilM_ :: Monad m => m Bool -> m a -> m ()
+untilM_ p f = unlessM_ p (f >> untilM_ p f)
diff --git a/src/Reaktor/Plugins/System.hs b/src/Reaktor/Plugins/System.hs
index 8ca468c..de96a61 100644
--- a/src/Reaktor/Plugins/System.hs
+++ b/src/Reaktor/Plugins/System.hs
@@ -10,7 +10,7 @@ import Control.Applicative
import Control.Concurrent (forkIO,threadDelay)
import Control.Concurrent.Async (race)
import Control.Exception
-import Control.Monad (forM_)
+import Control.Monad.Extended (forM_,untilM_)
import qualified Data.HashMap.Lazy as M
import qualified Data.List as L
import qualified Data.Text.Extended as T
@@ -217,9 +217,4 @@ signalProcessGroup' sig pgid =
hWithLines :: Handle -> (Text -> IO ()) -> IO ()
hWithLines h f = do
hSetBuffering h LineBuffering
- go `finally` hClose h
- where
- go =
- hIsEOF h >>= \case
- True -> return ()
- False -> T.hGetLine h >>= f >> go
+ untilM_ (hIsEOF h) (T.hGetLine h >>= f) `finally` hClose h