Overtone's 'at-at' library is a thin Clojure wrapper over ScheduledThreadPoolExecutor with a nice interface. I think you should be able to build a timer on top of it pretty easily.
https://github.com/overtone/at-at On Thursday, December 1, 2011 10:17:40 AM UTC-7, Bill Caputo wrote: > > Hi All, > > I am currently considering an approach similar to the following for > periodically sending an update to an agent and I'm looking for > feedback on whether there is anything wrong with it, whether it's > idiomatic clojure (sorry I'm in the pro-that-term camp) and whether > there are other pure-clojure alternatives I should consider (I also > realize there are java-based periodic timers I could use as well): > > (def *timer* (agent nil)) ; perhaps an atom instead? > (defn start-timer [ms a f] > (letfn [(tfn [m] (future (do (Thread/sleep ms) (send a f) (send > *timer* tfn))))] > (send *timer* tfn))) > > given an agent: > (def data (agent 0)) > > we could kick off an update every 3 seconds thusly: > (start-timer 3000 data #(inc %)) > > A real implementation would likely have to address further > considerations like stopping/cancelling the timer, not using a global > for the timer, and what happens if start-timer is called twice, but > this is the basic idea I'm considering... > > feedback welcome, > > thanks, > bill > > -- 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