Skip to content

Instantly share code, notes, and snippets.

@cstorey
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstorey/9991368 to your computer and use it in GitHub Desktop.
Save cstorey/9991368 to your computer and use it in GitHub Desktop.
(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