Created
March 5, 2014 17:07
-
-
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.
This file contains hidden or 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
(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