Re: Future

141 views
Skip to first unread message
Message has been deleted

Alex Engelberg

unread,
May 19, 2018, 6:38:28 PM5/19/18
to clo...@googlegroups.com
Not sure what's going on with shutdown-agents, but you could call (run! deref ...) to wait for all the futures to complete.

On Sat, May 19, 2018 at 3:29 PM Renata Soares <renata...@gmail.com> wrote:
Hello,

I am using future this way:

(doall (map #(future (<passing the function here>)  (range 1 max-size))))))

When the max-size is small like around 6, if I don't print (println (doall (map #(future (<passing the function here>)  (range 1 max-size))))))), the result <ranking> becomes empty

(Without print)

renata@renata:~/$ lein run
ranking  {}

(With print)
renata@renata:~/$$ lein run
(#object[clojure.core$future_call$reify__6962 0x6492fab5 {:status :ready, :val {:2 0, :4 0.0, :5 0, :1 2.5}}] #object[clojure.core$future_call$reify__6962 0x2c532cd8 {:status :ready, :val {:2 0}}] #object[clojure.core$future_call$reify__6962 0x294e5088 {:status :ready, :val {:2 0, :4 0.0, :5 0, :1 2.5, :3 1.0}}] #object[clojure.core$future_call$reify__6962 0x51972dc7 {:status :ready, :val {:2 0, :4 0.0}}] #object[clojure.core$future_call$reify__6962 0x3700ec9c {:status :ready, :val {:2 0, :4 0.0, :5 0}}])
ranking  {"1":2.5,"3":1.0,"5":0,"4":0.0,"2":0}

I am using (shutdown-agents) after the doall...

Any ideas why? I think it is because the futures aren't ready when (shutdown-agents) executes.

(When the max-size is big, run normally)

There is a way that I can wait for print the result until all futures are ready?

Thanks!

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Renata Soares

unread,
May 19, 2018, 6:42:04 PM5/19/18
to Clojure
It worked, thanks!

Moe Aboulkheir

unread,
May 19, 2018, 6:43:39 PM5/19/18
to clo...@googlegroups.com
(doall (pmap <function> (range ...))) may be a viable approach also, depending on the behaviour you want.  


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+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages