Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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