Skip to content

Instantly share code, notes, and snippets.

/core.clj Secret

Created December 29, 2013 11:09
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 anonymous/74d26af46b69add418c6 to your computer and use it in GitHub Desktop.
Save anonymous/74d26af46b69add418c6 to your computer and use it in GitHub Desktop.
(ns concurrent-http.core
(:gen-class)
(:require [org.httpkit.client :as http]))
(def list-size 200)
(def callbacks-counter (ref 0))
(def callbacks-finished (promise))
(def urls (take list-size (repeat "http://www.google.com")))
(defn handle-response [{:keys [status headers body error]}]
(dosync (alter callbacks-counter inc))
(if error
(println "Failed" @callbacks-counter)
(println "Done" @callbacks-counter))
(if (= @callbacks-counter list-size) (deliver callbacks-finished true))
)
(defn -main [& args]
(dorun (map #(http/get % handle-response) urls))
@callbacks-finished
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment