Skip to content

Instantly share code, notes, and snippets.

@msgodf
Last active Aug 29, 2015
Embed
What would you like to do?
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.
(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))))
@msgodf
Copy link
Author

msgodf commented Mar 5, 2014

I've intentionally namespace qualified each of the core.async functions here, so that it's a standalone sexpr without needing a require.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment