Created
December 30, 2010 18:28
-
-
Save tebeka/760094 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
(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