Created
December 3, 2013 22:11
-
-
Save aamedina/7778465 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
| (defn xhr | |
| [uri method content headers] | |
| (let [c (chan) | |
| m (mult c)] | |
| (if-let [cached (get-cached uri)] | |
| (let [tapped (tap m (chan))] | |
| (put! tapped cached) | |
| tapped) | |
| (if-let [source (get @outstanding-requests uri)] | |
| (tap source (chan)) | |
| (try (.send xhr-pool uri uri method | |
| (if (and (not (string? content)) | |
| (not (nil? content))) | |
| (stringify content) | |
| content) | |
| (clj->js headers) 50 | |
| #(do (put! c (handle-response (.-target %))) | |
| (swap! outstanding-requests dissoc uri)) | |
| 0) | |
| (swap! outstanding-requests assoc uri m) | |
| (tap m (chan)) | |
| (catch js/Error e nil)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment