From 413bac085db8b99dff6f0cc187473bc7c2999108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Wed, 16 Sep 2015 05:09:35 +0200 Subject: [PATCH] Fix sharing stdout Chan with multiple threads --- Language/Haskell/GhcMod/Monad.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Language/Haskell/GhcMod/Monad.hs b/Language/Haskell/GhcMod/Monad.hs index b29f8b7..da79779 100644 --- a/Language/Haskell/GhcMod/Monad.hs +++ b/Language/Haskell/GhcMod/Monad.hs @@ -78,14 +78,17 @@ withGhcModEnv' withCradle dir opts f = runGmOutT :: IOish m => Options -> GmOutT m a -> m a runGmOutT opts ma = do - gmo <- GhcModOut (optOutput opts) <$> liftIO newChan - runGmOutT' gmo ma + gmo@GhcModOut{..} <- GhcModOut (optOutput opts) <$> liftIO newChan + let action = runGmOutT' gmo ma + case ooptLinePrefix $ optOutput opts of + Nothing -> action + Just pfxs -> + gbracket_ (liftIO $ forkIO $ stdoutGateway pfxs gmoChan) + (const $ liftIO $ flushStdoutGateway gmoChan) + action runGmOutT' :: IOish m => GhcModOut -> GmOutT m a -> m a -runGmOutT' gmo@(gmoChan -> chan) ma = do - gbracket_ (liftIO $ forkIO $ stdoutGateway chan) - (const $ liftIO $ flushStdoutGateway chan) - (flip runReaderT gmo $ unGmOutT ma) +runGmOutT' gmo ma = flip runReaderT gmo $ unGmOutT ma -- | Run a @GhcModT m@ computation. runGhcModT :: (IOish m, GmOut m)