 (def c (chan))
 
 
-
+(chan)
 ;; We can attach listeners via take!
 
 (take! c (fn [v] (println v)))

(<!! (avg-cast-popularity 238))


(time (dotimes [x 10]
        (<!! (http-get "http://www.imdb.com/xml/find?json=1&q=ben+afleck"))))

(time (let [chans (doall (for [x (range 10)]
                             (http-get "http://www.imdb.com/xml/find?json=1&q=ben+afleck")))]
        (doseq [c chans]
          (<!! c))))





;;; Same HTTP Examples, but in the browser

(defn fixup-keys [x]
  (prewalk
   (fn [x]
     (if (map? x)
       (zipmap (map keyword (keys x))
               (vals x))
       x))
   x))

;; IO is a tad different in JS, so this function has to be re-written
;; for ClojureScript.
(defn http-get [url]
  (let [c (chan 1)]
    (goog.net.XhrIo/send url (fn [e]
                               (->> e
                                    .-target
                                    .getResponseJson
                                    js->clj
                                    fixup-keys
                                    (put! c))))
    c))


