Created
April 6, 2011 04:47
-
-
Save amalloy/905147 to your computer and use it in GitHub Desktop.
This file contains 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 process-urls [callback chunk-size stream] | |
(let [mcurl (MCurl.)] | |
(letfn [(add-handle | |
[next-thunk] | |
(when-let [[url cbdata] (next-thunk)] | |
(.add mcurl (Curl. url inner-callback cbdata)))) | |
(inner-callback | |
[info content data] | |
(add-handle #(or (apply callback args) | |
(stream))))]) | |
(dotimes [_ chunk-size] | |
(add-handle stream)) | |
(.finish mcurl))) | |
(defn simple-multi-curl [callback cbdata-fn chunk-size url-seq] | |
(let [url-ref (atom [url-seq nil])] ; remaining urls, next work item | |
(process-urls callback | |
chunk-size | |
(fn [] | |
(when-let [url (second (swap! url-ref | |
(comp (juxt rest first) | |
first)))] | |
[url (cbdata-fn url)]))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment