Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Future promises in Clojure hangs on me

When I run the following code it basically works how I intend it to, except that it hangs after the future is finished. What am I missing - some kind of "close agents/threads" call? How should I do this?

(def name-to-greet (promise))

(future
    (println "Hello," @name-to-greet))

(print "What is your name? ")
(flush)
(deliver name-to-greet (read-line))
like image 389
Torbjørn Avatar asked Aug 03 '10 04:08

Torbjørn


1 Answers

Futures use the agent thread pool, which uses non-daemon threads, which means Clojure won't shut down till you call (shutdown-agents). imho, this is bogus (see my comments here) and I've made suggestions that Rich said he would consider post-1.2 around this.

like image 82
Alex Miller Avatar answered Oct 10 '22 06:10

Alex Miller