Skip to content

Instantly share code, notes, and snippets.

@tebeka
Created December 30, 2010 18:28
Show Gist options
  • Save tebeka/760094 to your computer and use it in GitHub Desktop.
Save tebeka/760094 to your computer and use it in GitHub Desktop.
(use '[clojure.set :only (union)])
(def *count* (atom 10))
(defn get-entries []
(let [n (swap! *count* inc)]
(map (fn [i] {:id i :title (str "title " i)}) (range n))))
(defn process-entry [entry]
(println (:title entry)))
(defn get-new-entries [seen]
(let [seen? (complement seen)]
(filter #(seen? (:id %)) (get-entries))))
(defn poll [sleep-time]
(loop [seen #{}]
(let [entries (get-new-entries seen)]
(doall (map process-entry entries))
(println "================================")
(Thread/sleep sleep-time)
(recur (union seen (set (map :id entries)))))))
(poll 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment