Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@msgodf
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msgodf/9365059 to your computer and use it in GitHub Desktop.
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.
(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