{-# LANGUAGE CPP #-}
module Network.Wai.Handler.Warp.Windows
( windowsThreadBlockHack
) where
#if WINDOWS
import Control.Concurrent.MVar
import Control.Concurrent
import qualified Control.Exception
import Network.Wai.Handler.Warp.Imports
windowsThreadBlockHack :: IO a -> IO a
windowsThreadBlockHack act = do
var <- newEmptyMVar :: IO (MVar (Either Control.Exception.SomeException a))
void . forkIO $ Control.Exception.try act >>= putMVar var
res <- takeMVar var
case res of
Left e -> Control.Exception.throwIO e
Right r -> return r
#else
windowsThreadBlockHack :: IO a -> IO a
windowsThreadBlockHack :: IO a -> IO a
windowsThreadBlockHack = IO a -> IO a
forall a. a -> a
id
#endif