Skip to content

Instantly share code, notes, and snippets.

@msgodf
Created March 5, 2014 17:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msgodf/9371544 to your computer and use it in GitHub Desktop.
Save msgodf/9371544 to your computer and use it in GitHub Desktop.
Some code to test the behaviour of Clojure core.async's merge function. Given two channels that produce values at a given intervals, merge them and see whether the two sequences are interleaved or concatenated.
(require '[clojure.core.async :as async refer [<! go timeout])
(defn sleepy-val
[v t]
(go (<! (timeout t)) v))
;; Will this produce [1 2 3 1.5 2.5 3.5] or [1 1.5 2 2.5 3 3.5]?
(go
(prn (<! (async/into []
(async/merge [(.async/merge [(sleepy-val 1 1000)
(sleepy-val 2 2000)
(sleepy-val 3 3000)])
(async/merge [(sleepy-val 1.5 1500)
(sleepy-val 2.5 2500)
(sleepy-val 3.5 3500)])])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment