timeout returns a channel that closes after the given milliseconds. A receive on a closed channel yields nil, so an alt! clause on it runs when the deadline passes.
timeout
alt!
(require '[clojure.core.async :as async]) (def answers (async/chan)) (println (async/alt! answers ([v] v) (async/timeout 30) ([_] "timed out")))
Nothing is sent on answers, so the timeout wins.
answers
$ glj timeouts.glj timed out
Next example: Non-Blocking Operations.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.