> (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]
>  (let [exec (Executors/newCachedThreadPool)
>        pool (ExecutorCompletionService. exec)
>        futures (doall (for [x coll] (.submit pool #(f x))))] 
> (try 
>  (for [_ futures]  (.. pool take get))
> (finally (.shutdown exec)))))
>

It would be simpler (and possibly just a tad more performant) to use 
.invokeAll instead of (doall (for ... .submit)).

Also, your try-finally block doesn't make much sense when you consider that 
(for ...) returns *immediately*, without evaluating anything. The 
try-finally belongs to the place where you submit your tasks. There is no 
reason to delay shutting down the executor service after having submitted 
all tasks.

-- 
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

Reply via email to