I took a stab at it in pure core.async, unfortunately, it does not work; I
would be curious if anyone could explain why.
(use '[clojure.core.async :only [timeout <! go <!! alts!]])
(defn fib [n tmout]
(let [res (go (if (< n 2)
n
(let [r1 (<! (fib (- n 1) tmout))
r2 (<! (fib (- n 2) tmout))]
(when (and r1 r2) (+ r1 r2)))))]
(go
(first (alts! [res tmout])))))
(time (<!! (fib 30 (timeout 1000))))
By my reading, it seems like every go machine has a 50% chance of being
killed if the timeout has fired. I would expect it to take a little longer
than that to unwind all the existent go machine "stacks", but then it
should terminate. Not at all what happens. Although control returns
properly within the timeout, the cpu time per call to fib appears the same
regardless of what value of timeout I pick. I have several guesses about
what might be wrong, but probably just easier to ask if anyone knows what
is wrong. :)
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.