Futures begin executing their contents immediately, you don't have to
deref them to trigger the side effects. (perhaps you were thinking of
delay?)

I'm assuming you are using futures because email-request is an io-
blocking operation? The thing to note is that the body of a future
automatically runs in its own thread, so you could go ahead and just
do a regular map: (doall (map #(future (email-request %)) approved));
all the emails would then be sent in parallel threads.

On Sep 21, 4:06 pm, ronen <nark...@gmail.com> wrote:
> I was looking for a pure Clojure solution to run multiple non-
> dependant tasks on multiple threads, iv considered using Agent,
> Promises or Futures, yet the simplest cleanest succinct solution iv
> found is:
>
> (defn email-approved [approved]
>   (doall (pmap deref (for [req approved] (future (email-request
> req))))))
>
> The only thing that I don't like about it is the use of pmap, main
> since Im using the parallel mapping action just for side effects
> (triggering the consumptions of futures by derefing them).
>
> Iv seen solution that involve Java service executor and the Work
> project (https://github.com/getwoven/work), yet id rather achieve this
> in pure Clojure.
>
> Thanks
> Ronen

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