use System.Timeout

I'd forgotten this existed!
This commit is contained in:
Joey Hess 2012-11-14 11:53:23 -04:00
parent 481f32dfbc
commit 98d45cd383
2 changed files with 12 additions and 26 deletions

View file

@ -12,7 +12,6 @@ import Common
import Control.Concurrent
import Control.Exception
import Control.Concurrent.Async
import System.Posix.Terminal
import System.Posix.Signals
@ -46,19 +45,6 @@ unboundDelay time = do
threadDelay $ fromInteger maxWait
when (maxWait /= time) $ unboundDelay (time - maxWait)
{- Runs an action until a timeout is reached. If it fails to complete in
- time, or throws an exception, returns a Left value.
-
- Note that if the action runs an unsafe foreign call, the signal to
- cancel it may not arrive until the call returns. -}
runTimeout :: Seconds -> IO a -> IO (Either SomeException a)
runTimeout secs a = do
runner <- async a
controller <- async $ do
threadDelaySeconds secs
cancel runner
cancel controller `after` waitCatch runner
{- Pauses the main thread, letting children run until program termination. -}
waitForTermination :: IO ()
waitForTermination = do