alt!!

added

ns
clojure.core.async

type
macro

(alt!! & clauses)

Like alt!, except as if by alts!!, will block until completed, and
not intended for use in (go ...) blocks.

                ;; This example is taken from Timothy Baldridge's `core.async` course on Udemy
;; https://www.udemy.com/communicating-sequential-processes-with-coreasync/learn/v4/overview

;; Create two channels, c1 and c2
(let [c1 (chan 1)
      c2 (chan 1)]
  ;; Put a value in each channel
  (>!! c1 42)
  (>!! c2 44)
  (thread
    ;; Take a value from one of the channels.
    ;; - If the value is taken from c1, return the keyword :c1 and channel c1
    ;; - Analogously for c2
    (let [[v c] (alt!! [c1] [:c1 c1]
                       [c2] [:c2 c2])]
      ;; Print the returned keyword and whether the value was taken from c1 or c2
      (println "Value: " v)
      (println "Chan 1?: " (= c1 c))
      (println "Chan 1?: " (= c2 c)))))