On Thu, Oct 8, 2009 at 7:49 PM, John Harrop <jharrop...@gmail.com> wrote:
> You might be able to do better than that, and dispense entirely with the > separate polling thread. > Confirmed: (def x (agent {:polling false :message "foo"})) (defn poll [m] (when (:polling m) (prn (:message m)) (Thread/sleep 1000) (send-off *agent* poll)) m) (defn set-message [m mess] (assoc m :message mess)) (defn start [m] (send-off *agent* poll) (assoc m :polling true)) (defn stop [m] (assoc m :polling false)) (send-off x start) The message "foo" should start repeating in the standard-output monitor window of your IDE. (send-off x set-message "bar") The message "bar" should start repeating in the standard-output monitor window of your IDE, in place of "foo". (send-off x stop) The output should stop, and look like this: "foo" "foo" "foo" "foo" "bar" "bar" "bar" with possibly different numbers of repetitions. Seems to indicate that this strategy works beautifully for a periodically-repeating behavior that accepts state-change messages, including start and stop signals. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---