On 02/07/13 18:30, Brian Kirkbride wrote:
In the past I had used promises that were fulfilled by a
FixedThreadPool. But that's a lot of setup and teardown that distracts
from what you're actually trying to achieve.
no it's not...you define it once you use it forever! :)
(defn pool-map
"A saner, more disciplined version of pmap.
Submits jobs eagerly but polls for results lazily.
Don't use if original ordering of 'coll' matters."
([f coll threads]
(let [exec (Executors/newFixedThreadPool threads)
pool (ExecutorCompletionService. exec)
futures (try (mapv (fn [x] (.submit pool #(f x))) coll)
(finally (.shutdown exec)))]
(repeatedly (count futures) #(.. pool take get))))
([f coll]
(pool-map f coll (+ 2 cpu-no))))
Jim
--
--
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
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.