Skip to content

Instantly share code, notes, and snippets.

@mwilliams
Created October 19, 2010 19:28
Show Gist options
  • Save mwilliams/634894 to your computer and use it in GitHub Desktop.
Save mwilliams/634894 to your computer and use it in GitHub Desktop.
(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