control-timeout 0.1.1 → 0.1.2
raw patch · 2 files changed
+11/−10 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Control.Timeout: addTimeoutAtomic :: Float -> (IO ()) -> IO (STM TimeoutTag)
+ Control.Timeout: addTimeoutAtomic :: Float -> IO (IO () -> STM TimeoutTag)
Files
- Control/Timeout.hs +10/−9
- control-timeout.cabal +1/−1
Control/Timeout.hs view
@@ -104,7 +104,7 @@ -> IO () timeoutThread id targetTime = do currentTime <- getPOSIXTime- let deltausecs = truncate $ fromRational $ toRational ((currentTime - targetTime) * 1000000)+ let deltausecs = truncate $ fromRational $ toRational ((targetTime - currentTime) * 1000000) when (deltausecs > 0) $ threadDelay deltausecs atomically (do (id', _) <- readTVar signal@@ -121,7 +121,7 @@ -> (IO ()) -- ^ the action to perform -> IO TimeoutTag addTimeout delta action =- addTimeoutAtomic delta action >>= atomically+ addTimeoutAtomic delta >>= (\x -> atomically $ x action) -- | Similar in function to addTimeout above, this call splits the IO and STM -- parts of the process so that a timeout can be added atomically. Consider@@ -138,13 +138,12 @@ -- then we don't have the TimeoutTag to add to the bookkeeping structure and we -- would need another TVar, or some such, to fill in later. addTimeoutAtomic :: Float -- ^ the number of seconds in the future to perform the action- -> (IO ()) -- ^ the action to perform- -> IO (STM TimeoutTag) -- ^ an action to add the timeout and return the tag-addTimeoutAtomic delta action = do+ -> IO (IO () -> STM TimeoutTag) -- ^ an action to add the timeout and return the tag+addTimeoutAtomic delta = do currentTime <- getPOSIXTime let future = currentTime + (fromRational $ toRational delta)- stmAction :: STM TimeoutTag- stmAction = do+ stmAction :: IO () -> STM TimeoutTag+ stmAction action = do m <- readTVar timeouts case Map.lookup future m of Nothing -> do writeTVar timeouts $ Map.insert future [(0, action)] m@@ -215,5 +214,7 @@ case mthid of Nothing -> return () Just x -> killThread x- tid <- forkIO $ timeoutThread nextTag minTimeout- timeoutManagerThread tm signal minTimeout $ Just tid+ tid <- case minTimeout of+ 0 -> return Nothing+ x -> forkIO (timeoutThread nextTag minTimeout) >>= return . Just+ timeoutManagerThread tm signal minTimeout tid
control-timeout.cabal view
@@ -1,5 +1,5 @@ name: control-timeout-version: 0.1.1+version: 0.1.2 license: BSD3 license-file: LICENSE author: Adam Langley <agl@imperialviolet.org>