@hackage / ticker

A concurrent utility inspired by Ticker in golang

Latest1.0.0

About

Metadata

  • Last updated , by syocy
  • License BSD-3-Clause
  • Categories Concurrency
  • Maintained by: osmium.k@gmail.com

  • Lottery factor: 0

Links

Installation

Tested Compilers

  1. 8.0.2

Readme

ticker

A utility of concurrent programming in Haskell, inspired by Ticker in Go.

import Control.Concurrent.Ticker (newTicker)
import Control.Concurrent.Chan (getChanContents)
import Control.Concurrent.Async (async, cancel)
import Control.Monad (forM_)

main :: IO ()
main = do
  (chan, cancelTicker) <- newTicker (10^3 * 100) -- tick rate: 100ms
  chanStream <- getChanContents chan
  thread <- async $ forM_ chanStream $ \_ -> do
    putStr "Tick!"
  threadDelay (10^3 * 350) -- wait 3 ticks
  putStrLn ""
  cancel thread
  cancelTicker
  
-- Tick!Tick!Tick!

More functions are defined in src/Control/Concurrent/Ticker.hs.