Skip to content

Instantly share code, notes, and snippets.

@jraines
Created October 7, 2015 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 jraines/4d2bc117e83fa5b0f9af to your computer and use it in GitHub Desktop.
Save jraines/4d2bc117e83fa5b0f9af to your computer and use it in GitHub Desktop.
core.async Promise.all equivalent attempt
(go (println (<! (a/into [] (a/merge (map original-image-dimensions (:items @app-state)))))))
(defn original-image-dimensions [item]
(let [sub clojure.string/replace
image_url (sub (:large_default_image_url item) #"large" "original")
img (js/Image.)
out (chan)]
(aset img "onload" (fn [] (this-as image
(put! out {:height (.-height image)
:width (.-width image)})
(a/close! out))))
(aset img "src" image_url)
out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment