readResponse :: Process -> Int -> ProcessM Response
readResponse p i = do
        someInput <- lift$ hWaitForInput (h_out p) 2000
        lift$ when (not someInput)$ ioError$ userError$ "process "++show i++" blocked" 
        line <- lift$ hGetLine (h_out p)
        r <- lift$ evaluate (read line) `catch` 
                  (\e -> ioError$ userError$ "failed reading response: "++show line++" with "++show (e :: SomeException))
        unless (r==Idle)$ addResponse r i
        return r


-- | @loopWhileM p io@ performs @io@ repeteadly while its result satisfies @p@.
-- Yields the first offending result.
readResponse :: Process -> Int -> ProcessM Response
readResponse p i = do
        someInput <- lift$ hWaitForInput (h_out p) 2000
        lift$ when (not someInput)$ ioError$ userError$ "process "++show i++" blocked" 
        line <- lift$ hGetLine (h_out p)
        r <- lift$ evaluate (read line) `catch` 
                  (\e -> ioError$ userError$ "failed reading response: "++show line++" with "++show (e :: SomeException))
        unless (r==Idle)$ addResponse r i
        return r


-- | @loopWhileM p io@ performs @io@ repeteadly while its result satisfies @p@.
-- Yields the first offending result.
readResponse p i = do
        someInput <- lift$ hWaitForInput (h_out p) 2000
        lift$ when (not someInput)$ ioError$ userError$ "process "++show i++" blocked" 
        line <- lift$ hGetLine (h_out p)
        r <- lift$ evaluate (read line) `catch` 
                  (\e -> ioError$ userError$ "failed reading response: "++show line++" with "++show (e :: SomeException))
        unless (r==Idle)$ addResponse r i
        return r


-- | @loopWhileM p io@ performs @io@ repeteadly while its result satisfies @p@.
-- Yields the first offending result.