philipbohun.com

Glojure by Example: Tickers

time.NewTicker sends on its C channel at an interval until Stop. The channel is a Go channel, so receive with go/recv. Stop the ticker when the loop is done so it can be collected.

(def ticker (time.NewTicker (* 10 time.Millisecond)))
(dotimes [_ 3]
  (go/recv (.C ticker))
  (println "tick"))
(.Stop ticker)
(println "stopped")

Three ticks, then the ticker is stopped.

$ glj tickers.glj
tick
tick
tick
stopped

Next example: Worker Pools.