Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syocy/ticker-hs
A utility for concurrent programming in Haskell, insipired by Ticker in golang.
https://github.com/syocy/ticker-hs
Last synced: about 2 months ago
JSON representation
A utility for concurrent programming in Haskell, insipired by Ticker in golang.
- Host: GitHub
- URL: https://github.com/syocy/ticker-hs
- Owner: syocy
- License: bsd-3-clause
- Created: 2017-08-19T18:53:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-13T07:35:24.000Z (over 7 years ago)
- Last Synced: 2024-04-25T23:31:18.733Z (8 months ago)
- Language: Haskell
- Size: 6.84 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Travis](https://img.shields.io/travis/syocy/ticker-hs.svg)](https://travis-ci.org/syocy/ticker-hs)
[![Hackage](https://img.shields.io/hackage/v/ticker.svg)](https://hackage.haskell.org/package/ticker)# ticker
A utility of concurrent programming in Haskell, inspired by [Ticker](https://golang.org/pkg/time/#Ticker) in Go.
```haskell
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`.