timeout

added

ns
clojure.core.async

type
function

(timeout msecs)

Returns a channel that will close after msecs

                user=> (go-loop [seconds (atom 0)
                 add-seconds! #(swap! seconds + %)]
         (println "Waiting 1 second")
         (<! (timeout 1000))
         (add-seconds! 1)
         (println "Waiting 2 seconds")
         (<! (timeout 2000))
         (add-seconds! 2)
         (println
          (format "Waited %s seconds"
                  @seconds))) 

#<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@67ddcb0e>

;; Waiting 1 second

;; Waiting 2 seconds

;; Waited 3 seconds

            
                user=> (doseq [n (range 10)
               :let [i (-> n
                           inc
                           range
                           rand-nth)]]                    
         (go
           (<! (timeout (* i 1000)))
           (println n)))
nil
5
3
0
6
4
7
1
2
9
8