alts!!

added

ns
clojure.core.async

type
function

(alts!! ports & {:as opts})

Like alts!, except takes will be made as if by <!!, and puts will
be made as if by >!!, will block until completed, and not intended
for use in (go ...) blocks.

                user> (let [chans (partition-all 2
                                 (interleave
                                  ["Bob"
                                   "Jane"
                                   "GuyGirl22"]
                                  (for [_ (range 3)]              
                                    (chan))))
            [owner port] (rand-nth chans)
            chans-only (mapv second chans)]
        
        (go
          (<! (timeout 1500))
          (>! port
              (str owner ": First!!!")))

        (let [[v p] (alts!! chans-only)]
          (println "Message: " v "\
From Object: " p)))

;; Message:  Bob: First!!! 
;; From Object:  #<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@70c61ad7>
;; nil

            
                (require '[clojure.core.async :as async])

;; n.b. alts!! returns a *pair* of [value channel-where-value-came-from]

; a channel with a single value ready in the queue
(def c (async/chan))
(async/put! c "foo")

(println (async/alts!! [(async/timeout 2000) c]))
;; => ["foo" <c-channel>]

; no more values, so we will timeout
(println (async/alts!! [(async/timeout 2000) c]))
;; => [nil <timeout-channel>]