Advertisement
Guest User

Untitled

a guest
May 7th, 2010
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 3.95 KB | None | 0 0
  1. (defn start-handler [[nme definition]]                                                                                                                                                                    
  2.   (let [queue (new LinkedBlockingQueue)                                                                                                                                                                  
  3.         handler (:handler definition)                                                                                                                                                                    
  4.         condition (:cond definition)                                                                                                                                                                      
  5.         name (str "handler" nme)]                                                                                                                                                                        
  6.     (println "starting" name)                                                                                                                                                                            
  7.     (start-thread #(handler (queue-seq queue)) name)                                                                                                                                                      
  8.     #(if (condition %) (.put queue %))))                                                                                                                                                                  
  9.                                                                                                                                                                                                          
  10. (defn filter-with-date [e]                                                                                                                                                                                
  11.   (not                                                                                                                                                                                                    
  12.     (or (nil? (:date e))                                                                                                                                                                                  
  13.         (= (:name e) "-"))))                                                                                                                                                                              
  14.                                                                                                                                                                                                          
  15. (defn printer []                                                                                                                                                                                          
  16.   (struct-map handler                                                                                                                                                                                    
  17.     :cond filter-with-date                                                                                                                                                                                
  18.     :handler (fn [es]                                                                                                                                                                                    
  19.                (doseq [e es]                                                                                                                                                                              
  20.                  (println e)))))
  21.  
  22. ; with a different thread doing
  23. (start-handler [:print-handler (printer)])
  24. ; and shoving items onto the LBQ with the returned function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement