File: Windows.hs

package info (click to toggle)
haskell-warp 3.0.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 300 kB
  • ctags: 2
  • sloc: haskell: 2,890; makefile: 8
file content (24 lines) | stat: -rw-r--r-- 568 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{-# LANGUAGE CPP #-}
module Network.Wai.Handler.Warp.Windows
  ( windowsThreadBlockHack
  ) where

#if WINDOWS
import Control.Exception
import Control.Concurrent.MVar
import Control.Concurrent
import Control.Monad

windowsThreadBlockHack :: IO a -> IO a
windowsThreadBlockHack act = 
  do
    var <- newEmptyMVar :: IO (MVar (Either SomeException a))
    void . forkIO $ try act >>= putMVar var
    res <- takeMVar var
    case res of
      Left  e -> throwIO e
      Right r -> return r
#else
windowsThreadBlockHack :: IO a -> IO a
windowsThreadBlockHack = id
#endif