Last active
January 13, 2016 21:06
-
-
Save caryfitzhugh/11400d16f61acf35a03b to your computer and use it in GitHub Desktop.
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]) | |
(def file ["a" "b" {:url "http://ip.jsontest.com/"} "d" "e" {:url "http://time.jsontest.com"}]) | |
(println "Loaded file..." (pr-str file)) | |
(defmacro while-let | |
"Repeatedly executes body while test expression is true, evaluating the body with binding-form bound to the value of test." | |
[[form test] & body] | |
`(loop [~form ~test] | |
(when ~form | |
~@body | |
(recur ~test)))) | |
(let [output (async/chan) | |
v (println "Creating channels") | |
channels (map (fn [line] | |
(let [rendered-line (async/chan 1)] | |
(async/go | |
(if (map? line) | |
(do | |
;; Would go do an HTTP request here | |
(async/<! (async/timeout 1000)) | |
(async/>! rendered-line (str "HTTP:" (:url line))) | |
(async/close! rendered-line)) | |
(do | |
(async/>! rendered-line line) | |
(async/close! rendered-line)))) | |
rendered-line) | |
) file) | |
] | |
(let [result (atom "")] | |
(async/go | |
(doseq [channel channels] | |
(swap! result str "\n" (async/<! channel)) | |
)) | |
(println @result)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment