On Sun, Nov 1, 2009 at 7:39 PM, Jonathan Smith
<jonathansmith...@gmail.com>wrote:
>
> Maybe I'm confused, but can't you just do a regular java thread for
> this?
>
> (defn periodicly [fun time]
>  "starts a thread that calls function every time ms"
>  (let [thread (new Thread (fn [] (loop [] (fun) (Thread/sleep time)
> (recur))))]
>    (.start thread)
>    thread))
>
> (periodicly #(println "foo foo foo") 3000)
>
> I'm not really sure about the error handling thing, but I guess you
> could wrap the function in a try-catch where it reinitialized itself.
> (although I guess that could get dangerous if you start throwing a lot
> of errors).


The actor code makes it easy to start, stop, and modify the periodic task
and not just to start it. :)

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