@@ -3,6 +3,7 @@ module Timeout
33 , Handle
44 , initialize
55 , register
6+ , registerKillThread
67 , tickle
78 , pause
89 , resume
@@ -10,7 +11,7 @@ module Timeout
1011 ) where
1112
1213import qualified Data.IORef as I
13−import Control.Concurrent (forkIO, threadDelay)
14+import Control.Concurrent (forkIO, threadDelay, myThreadId, killThread)
1415import Control.Monad (forever)
1516import qualified Control.Exception as E
1617
@@ -52,6 +53,11 @@ register (Manager ref) onTimeout = do
5253 I.atomicModifyIORef ref (\x -> (h : x, ()))
5354 return h
5455
56+registerKillThread :: Manager -> IO Handle
57+registerKillThread m = do
58+ tid <- myThreadId
59+ register m $ killThread tid
60+
5561tickle, pause, resume, cancel :: Handle -> IO ()
5662tickle (Handle _ iactive) = I.writeIORef iactive Active
5763pause (Handle _ iactive) = I.writeIORef iactive Paused