Last active
August 29, 2015 13:57
-
-
Save msgodf/9365059 to your computer and use it in GitHub Desktop.
Just a quick demo of how the Clojure core.async merge function works. I wanted to check that the values from the input channels appear in the merged channel straight away.
This file contains 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
(clojure.core.async/go | |
(let [sleepy-val (fn [v t] (clojure.core.async/go | |
(clojure.core.async/<! (clojure.core.async/timeout t)) | |
v)) | |
chans (clojure.core.async/merge (map #(sleepy-val % (rand-int 3000)) | |
(range 10)))] | |
(while (when-let [v (clojure.core.async/<! chans)] | |
(prn v) | |
v)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've intentionally namespace qualified each of the core.async functions here, so that it's a standalone sexpr without needing a require.