-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A concurrent utility inspired by Ticker in golang -- -- A concurrent utility inspired by Ticker in golang @package ticker @version 1.0.0 module Control.Concurrent.Ticker -- | Create a new ticker. -- --
-- >>> import Control.Concurrent.Chan (getChanContents) -- -- >>> import Control.Monad (forM_) -- -- >>> import System.Timeout (timeout) -- -- >>> (chan, cancelTicker) <- newTicker $ 10^3 * 100 -- -- >>> chanStream <- getChanContents chan -- -- >>> _ <- timeout (10^3 * 350) $ forM_ chanStream (\_ -> putStr "Tick!") -- Tick!Tick!Tick! -- -- >>> cancelTicker --newTicker :: Int -> IO (Chan (), IO ()) -- | Create a new ticker and pass a Chan () of the ticker to the -- supplied function. The ticker thread will be closed automatically. -- --
-- >>> import Control.Concurrent.Chan (getChanContents)
--
-- >>> import Control.Monad (forM_)
--
-- >>> import System.Timeout (timeout)
--
-- >>> :{
-- withTicker (10^3 * 100) $ \chan -> do
-- chanStream <- getChanContents chan
-- _ <- timeout (10^3 * 350) $ forM_ chanStream (\_ -> putStr "Tick!")
-- return ()
-- :}
-- Tick!Tick!Tick!
--
withTicker :: Int -> (Chan () -> IO a) -> IO a
-- | A variant of the newTicker that uses getCPUTime
-- instead of threadDelay internally.
-- | Deprecated: It doesn't work well.
newCPUTimeTicker :: Int -> IO (Chan (), IO ())