@@ -1,12 +1,19 @@
1+{-# LANGUAGE DeriveDataTypeable #-}
2+
13module Network.Wai.Handler.Warp.Thread (
24 forkIOwithBreakableForever
35 , breakForever
46 ) where
57
68import Control.Concurrent (forkIO)
9+import Control.Exception (handle, throw, mask_, Exception)
710import Control.Monad (void, forever)
8−import Control.Exception (handle, throw, mask_, SomeException, AsyncException(ThreadKilled))
911import Data.IORef
12+import Data.Typeable
13+
14+data BreakForever = BreakForever deriving (Show, Typeable)
15+
16+instance Exception BreakForever
1017
1118forkIOwithBreakableForever :: a -> (IORef a -> IO ()) -> IO (IORef a)
1219forkIOwithBreakableForever ini action = do
@@ -14,8 +21,8 @@ forkIOwithBreakableForever ini action = do
1421 void . forkIO . handle stopPropagation . forever . mask_ $ action ref
1522 return ref
1623
17−stopPropagation :: SomeException -> IO ()
24+stopPropagation :: BreakForever -> IO ()
1825stopPropagation _ = return ()
1926
2027breakForever :: IORef a -> IO a
21−breakForever ref = atomicModifyIORef ref $ \x -> (throw ThreadKilled, x)
28+breakForever ref = atomicModifyIORef ref $ \x -> (throw BreakForever, x)