future also uses the same threadpool as agents, so once you call
future the threadpool spins up, and just sort of sits around for a
while before the jvm decides to exit, which is why the program would
sit around for 50 seconds

On Wed, Nov 25, 2009 at 10:30 AM, Hong Jiang <h...@hjiang.net> wrote:
> Thanks for your replies David and Sean. Yes, I made a mistake thinking
> that future takes a function and its arguments, so the function was
> never called in my program.
>
> On Nov 25, 8:21 am, David Brown <cloj...@davidb.org> wrote:
>> On Tue, Nov 24, 2009 at 09:04:38PM -0800, Hong Jiang wrote:
>> >Hi all,
>>
>> >I'm new to Clojure and playing with small programs. Today I wrote a
>> >snippet to figure out how future works:
>>
>> >(defn testf []
>> >  (let [f (future #(do
>> >                     (Thread/sleep 5000)
>> >                     %)
>> >                  5)
>> >        g 7]
>> >    (+ g @f)))
>>
>> You don't ever evaluate the function containing the sleep, you just
>> create it, and then immediately return 5.
>>
>> Future contains an explicit do, so you can just do the steps in the
>> future:
>>
>>      [f (future
>>           (Thread/sleep 5000)
>>          5)
>>          ...
>>
>> Or, if you want to get the function call in, you'll need to call it:
>>
>>      [f (future (#(do (Thread/sleep 5000) %) 5)) ...]
>>
>> David
>
> --
> 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



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

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