Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; The following code has no memory leak
- (defn start-handler [[nme definition]]
- (let [queue (new LinkedBlockingQueue)
- handler (:handler definition)
- condition (:cond definition)
- name (str "handler" nme)]
- (println "starting" name)
- (start-thread #(handler queue) name)
- #(if (condition %) (.put queue %))))
- (defn filter-with-date [e]
- (not
- (or (nil? (:date e))
- (= (:name e) "-"))))
- (defn printer []
- (struct-map handler
- :cond filter-with-date
- :handler (fn [queue]
- (loop []
- (println (.take queue))
- (recur)))))
- ; Another thread does
- (start-handler [:print-handler (printer)])
- ; and then pushes stuff into the LBQ using the returned function
Advertisement
Add Comment
Please, Sign In to add comment