openFifo :: FilePath -> IO Pipe
openFifo fp = do
  mvar <- newEmptyMVar
  let readF fd = forever (fmap fst (fdRead fd 100) >>= putMVar mvar)
        `Exception.catch`
        \ e -> const (threadDelay 100) (e :: Exception.IOException)
  let reader = forever $ do
                fd <- openFd fp ReadWrite Nothing defaultFileFlags
                readF fd `Exception.catch`
                 \ e -> closeFd fd >>
                        if isEOFError e then reader
                        else throwIO (e :: Exception.IOException)
  return (reader, mvar)
openFifo :: FilePath -> IO Pipe
openFifo fp = do
  mvar <- newEmptyMVar
  let readF fd = forever (fmap fst (fdRead fd 100) >>= putMVar mvar)
        `Exception.catch`
        \ e -> const (threadDelay 100) (e :: Exception.IOException)
  let reader = forever $ do
                fd <- openFd fp ReadWrite Nothing defaultFileFlags
                readF fd `Exception.catch`
                 \ e -> closeFd fd >>
                        if isEOFError e then reader
                        else throwIO (e :: Exception.IOException)
  return (reader, mvar)
openFifo fp = do
  mvar <- newEmptyMVar
  let readF fd = forever (fmap fst (fdRead fd 100) >>= putMVar mvar)
        `Exception.catch`
        \ e -> const (threadDelay 100) (e :: Exception.IOException)
  let reader = forever $ do
                fd <- openFd fp ReadWrite Nothing defaultFileFlags
                readF fd `Exception.catch`
                 \ e -> closeFd fd >>
                        if isEOFError e then reader
                        else throwIO (e :: Exception.IOException)
  return (reader, mvar)