philipbohun.com

Glojure by Example: Timers

time.After returns a Go channel that receives one time value after the duration. go/recv waits for it. The received value is a timestamp, which this program ignores. time.Sleep pauses the calling goroutine directly.

(let [[_ ok] (go/recv (time.After (* 10 time.Millisecond)))]
  (println "fired" ok))
(time.Sleep (* 10 time.Millisecond))
(println "slept")

The receive flag is true when a value arrives.

$ glj timers.glj
fired true
slept

Next example: Tickers.