Created
October 19, 2010 19:28
-
-
Save mwilliams/634894 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 dispatch-generator | |
"Return a fn to handle a completed response." | |
[feed-key feed-url response-callback] | |
(fn [state] | |
(let [code (-> (c/status state) :code) | |
headers (c/headers state) | |
body (-> (c/body state) .toString)] | |
(response-callback feed-key | |
feed-url | |
code | |
headers | |
body) | |
[true :continue]))) | |
(defn fetch | |
"fetch a feed for updates. Responses are handled asynchronously by the provided callback. | |
The callback should accept five arguments: k, u, response code, headers, and body." | |
[[k u & headers] put-done] | |
(let [callbacks (merge async-req/*default-callbacks* | |
{:status status-check | |
:completed (dispatch-generator k u put-done)}) | |
req (async-req/prepare-request :get | |
u | |
:headers headers) | |
resp (apply async-req/execute-request | |
req | |
(apply concat callbacks))] | |
resp)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment