go-loop

added

ns
clojure.core.async

type
macro

(go-loop bindings & body)

Like (go (loop ...))

                (go-loop [seconds 1]
         (<! (timeout 1000))
         (print "waited" seconds "seconds")
         (recur (inc seconds)))

;;waited 1 seconds
;;waited 2 seconds
;;waited 3 seconds
;;...
            
                user=> (def c (chan 1))
#'user/c

user=> (go-loop []
         (let [x (<! c)]
           (println "Got a value in this loop:" x))
         (recur))

#<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@30df0e27>

user=> (doseq [n (range 3)] (put! c n))
nil
Got a value in this loop: 0
Got a value in this loop: 1
Got a value in this loop: 2