Last active
August 29, 2015 13:58
-
-
Save cstorey/9991368 to your computer and use it in GitHub Desktop.
Core.async version of https://gist.github.com/mneedham/9990977
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
(require '[clojure.core.async :refer [alt! <!! chan go-loop]]) | |
(defn events [quit-ch {perpage :perpage offset :offset orderby :orderby}] | |
(let [out-port (chan) | |
(go-loop [offset offset] | |
(let [res (client/get | |
(str "https://api.meetup.com/2/events?page=" perpage | |
"&offset=" offset | |
"&orderby=" orderby | |
"&status=upcoming,past&" | |
"&group_urlname=" MEETUP_NAME | |
"&key=" MEETUP_KEY) | |
{:as :json})] | |
(alt! | |
;; When the producer closes quit-ch, we're done. | |
quit-ch (close! out-port) | |
;; Otherwise fetch the next set of results. | |
[out-port res] (recur (+ perpage offset))))) | |
out-port)) | |
(let [quit-ch (chan) | |
event-ch (events quit-ch ...)] | |
(loop [result-set (<!! event-ch)] | |
(if (we-still-want-more-events result-set) | |
(recur (<!! event-ch)) | |
;; Close the quit channel, thereby halting the producer. | |
(close! quit-ch)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment