Hey Bill, I would have thought you would have to have a pretty good
reason for not using an executor for this?

(let [executor (Executors/newSingleThreadScheduledExecutor)]
  (.scheduleAtFixedRate executor your-func 0 3 TimeUnit/SECONDS))

On Thu, Dec 1, 2011 at 11:17 AM, Bill Caputo <logos...@gmail.com> 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

-- 
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

Reply via email to