SHARE
TWEET

Untitled

a guest Dec 7th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns rivershy
  2.   (:require [clojure.core.async :as a]))
  3.  
  4. (def c1 (a/chan 10))
  5. (def c2 (a/chan 10))
  6. (def cr (a/chan 10))
  7.  
  8. (a/onto-chan c1 ["a" "1" "c" "d" "q"])
  9. (a/onto-chan c2 ["a" "b" "c" "d" "e"])
  10.  
  11. (defn eq-chans [chans r]
  12.   (a/go-loop []
  13.     (let [val (fn [x] (a/<! x))
  14.           vals (map val chans)]
  15.       (when (apply = vals)
  16.         (a/>! r (first vals))
  17.         (recur)
  18.         )
  19.       )
  20.     )
  21.   )
  22.  
  23. (defn consumer []
  24.   (a/take! cr (fn [x] (println (str "received" x)) (consumer name))))
  25.  
  26. (eq-chans []c1 c2] cr)
  27.  
  28. (consumer)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top