on master help sign in
Defining an exception: BreakForever.
commitde0f05a35df5a924adff8ef59331ec84d33afc6f authorKazu Yamamoto <kazu@iij.ad.jp> dateTue 22 Oct 2013, 09:44 (13 years ago) parente550ddd
1 file changed+10−3
warp/Network/Wai/Handler/Warp/Thread.hs+10−3
warp/Network/Wai/Handler/Warp/Thread.hs+10−3
@@ -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)