-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Updatable one-shot timer polled with STM -- -- This library lets you create a one-shot timer, poll it using STM, and -- update it to ring at a different time than initially specified. -- -- It uses GHC event manager timeouts when available (GHC 7.2+, -- -threaded, non-Windows OS), yielding performance similar to -- threadDelay and registerDelay. Otherwise, it falls -- back to forked threads and threadDelay. @package stm-delay @version 0.1 -- | One-shot timer whose duration can be updated -- -- Suppose you are managing a network connection, and want to time it out -- if no messages are received in over five minutes. You can do something -- like this: -- --
--   import Control.Concurrent.Async (race_) -- from the async package
--   import Control.Concurrent.STM
--   import Control.Concurrent.STM.Delay
--   import Control.Exception
--   import Control.Monad
--   
--   manageConnection :: Connection -> IO Message -> (Message -> IO a) -> IO ()
--   manageConnection conn toSend onRecv =
--       bracket (newDelay five_minutes) cancelDelay $ \delay ->
--       foldr1 race_
--           [ do atomically $ waitDelay delay
--                fail "Connection timed out"
--           , forever $ toSend >>= send conn
--           , forever $ do
--               msg <- recv conn
--               updateDelay delay five_minutes
--               onRecv msg
--           ]
--     where
--       five_minutes = 5 * 60 * 1000000
--   
module Control.Concurrent.STM.Delay -- | A Delay is an updatable timer that rings only once. data Delay -- | Create a new Delay that will ring in the given number of -- microseconds. newDelay :: Int -> IO Delay -- | Set an existing Delay to ring in the given number of -- microseconds (from the time updateDelay is called), rather than -- when it was going to ring. If the Delay has already rung, do -- nothing. updateDelay :: Delay -> Int -> IO () -- | Set a Delay so it will never ring, even if updateDelay -- is used later. If the Delay has already rung, do nothing. cancelDelay :: Delay -> IO () -- | Block until the Delay rings. If the Delay has already -- rung, return immediately. waitDelay :: Delay -> STM () -- | Non-blocking version of waitDelay. Return True if the -- Delay has rung. tryWaitDelay :: Delay -> STM Bool instance Eq Delay