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.
time.After
go/recv
time.Sleep
(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.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.