Skip to content

Instantly share code, notes, and snippets.

@caryfitzhugh
Last active January 13, 2016 21:06
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 caryfitzhugh/11400d16f61acf35a03b to your computer and use it in GitHub Desktop.
Save caryfitzhugh/11400d16f61acf35a03b to your computer and use it in GitHub Desktop.
(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