-
-
Save vbedegi/7299564 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.core.async) | |
;this is the function you want to use | |
(defn lazy-channels [chs] | |
(lazy-seq (cons (let [ [v _] (alts!! chs)] v) (lazy-channels chs)))) | |
;now for the tesging | |
(def chs [ (chan) (chan) (chan) ]) ; the channels can come from anywhere, here we are using three channels for testing | |
(thread (dotimes [i 1000] | |
(>!! (rand-nth chs) (str "m-" i)))) ;add 1000 elements to a random selection of channels | |
;create a sequence | |
(def s (lazy-channels chs)) | |
;now consume, please note that this will block when no more data is available on the channels | |
(doseq [msg s] | |
(prn msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment