You can put the computation into a future, and cancel the future after the timeout.
BTW is it idiomatic to write to the timeout channel? I thought one should use something like (alts!! [c (timeout 1000)]). JW On Wednesday, January 22, 2014 11:30:23 AM UTC+1, puzzler wrote: > > So far, this is the only way I've figured out that works: > > (defn try-fib [n] > (let [ch (timeout 1000) > th (Thread. #(>!! ch (fib n))) > _ (.start th) > answer (<!! ch)] > (if answer answer > (do (.stop th) nil)))) > > But there are a couple bazillion sources that say you should never, ever > stop a thread. Is it perfectly safe in a situation like this where the > thread is running a pure function with no mutable state? > > Is there a better approach that is more integrated with core.async and > more safe? > -- -- 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 --- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.