I'm running into a strange problem that I can't see the bottom of.
Wonder if someone can explain why I'm seeing the behavior I'm
seeing...
I have a function that uses a Java timer to run a function and can
also check the results of that function by passing in an optional test
function
(defn timed-agent [limit timed-func & test-func]
(let [a (agent 0)
;; test-func can be defined here
agent-func (fn [v] (let [result (timed-func v)]
(when test-func (test-func result)) (inc
v)))
t (java.util.Timer.)
tt (proxy [java.util.TimerTask] [] (run [] (send-off a agent-
func)))]
(set-validator! a #(> limit %))
(.scheduleAtFixedRate t tt 1000 1000)))
This works if I don't pass in a test function
(timed-agent 10 prn)
You will see output of 0 1 2 3...9
This does not work if I pass in a test function
(timed-agent 10 prn prn)
You will see output of 0 and nothing more
This does work if I define test-func within the function (on the
commented line) - ex, as prn
You will see 0 nil 1 nil 2 nil...9 nil
First question - why can't I pass in a test function and have the
timer loop work as expected
Second question - is there a better way for me to set an upper bound
on a Java timer using Clojure?
--
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