Kill timeout thread if working finished in time.

This commit is contained in:
David 2019-03-01 11:27:39 +01:00
commit 85e4a59a7c

View file

@ -98,11 +98,12 @@ withTimeout queue conn t action = do
worker <- forkIO (action >> putMVar finished ()) worker <- forkIO (action >> putMVar finished ())
timer <- forkIO $ do timer <- forkIO $ do
threadDelay (10^6 * t) threadDelay (10^6 * t)
putMVar finished ()
putStrLn "Timeout" putStrLn "Timeout"
killThread worker killThread worker
_ <- getChanContents queue _ <- getChanContents queue
writeChan queue $ T.pack $ "Error" ++ "Timeout" writeChan queue $ T.pack $ "Error" ++ "Timeout"
putMVar finished ()
takeMVar finished `onException` do takeMVar finished `onException` do
killThread worker killThread worker
killThread timer killThread timer