ticker: A concurrent utility inspired by Ticker in golang

[ bsd3, concurrency, library ] [ Propose Tags ]

A concurrent utility inspired by Ticker in golang


[Skip to Readme]

Modules

[Index]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.0
Change log CHANGELOG.md
Dependencies async (>=2.0 && <3), base (>=4.7 && <5), safe-exceptions (>=0.1) [details]
License BSD-3-Clause
Copyright 2017 OSANAI Kazuyoshi
Author OSANAI Kazuyoshi
Maintainer osmium.k@gmail.com
Revised Revision 1 made by syocy at 2017-08-22T07:20:08Z
Category Concurrency
Home page https://github.com/syocy/ticker-hs
Bug tracker https://github.com/syocy/ticker-hs/issues
Source repo head: git clone https://github.com/syocy/ticker-hs
Uploaded by syocy at 2017-08-21T16:22:44Z
Distributions NixOS:1.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1125 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-08-21 [all 1 reports]

Readme for ticker-1.0.0

[back to package description]

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.