Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Documentation
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
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!