> (defn pool-map > "A saner, more disciplined version of pmap. Not lazy at all. > Don't use if original ordering of 'coll' matters!" > [f coll] > (let [cpus (.. Runtime getRuntime availableProcessors) > exec (Executors/newFixedThreadPool cpus) > pool (ExecutorCompletionService. exec) > futures (for [x coll] (.submit pool #(f x)))] > (try > (doall (for [e futures] (.. pool take get))) > (finally (.shutdown exec))))) >
What exactly is the value provided by ExecutorCompletionService? To my eyes, this function is quite similar to (comp doall pmap), but with shuffled result. There is no advantage to using the lazy approach to submitting tasks: you could have simply used invokeAll: (defn pool-map [f coll] (let [exec (Executors/newFixedThreadPool (.availableProcessors (Runtime/getRuntime))) r (.invokeAll exec (for [x coll] #(f x)))] (try (doall (map #(.get %) r)) (finally (.shutdown exec))))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en