Hi Thomas,

You need to execute this line:
  (dosync (ref-set location (read-json (slurp url))))
every time you want to re-query the string.

To do this periodically you could do something like this [1]:

(import '(java.util TimerTask Timer))
(let [task (proxy [TimerTask] []
   (run [] (dosync (ref-set location (read-json (slurp url))))))]
     (. (new Timer) (schedule task (long 15000))))

[1]: http://www.mail-archive.com/clojure@googlegroups.com/msg00136.html

Cheers,
Ivan.


On 6 June 2011 14:51, Thomas <th.vanderv...@gmail.com> wrote:

> Hi All,
>
> I recently started playing with Clojure and loving it... and finding
> of course the usual problem(s). In my little program I am reading a
> JSON string that changes regularly, up to once every 15 seconds or so,
> through HTTP. I know that the string changes, I can see that in my
> browser and I can see things change in another (web)app that consumes
> the string. My current code looks like this:
>
> (def url "http://xxxx.xxxxx.xx"; )
> (def location (ref nil))
> (dosync (ref-set location (read-json (slurp url))))
>
> My problem is, that once I have started the program it reads the
> string successfully, but subsequent reads are the same, even though I
> know that the string has changed. What should I do differently?  (I
> loop through the function with a bit of code from Rich Hickeys
> ants.clj)
>
> TIA
> Thomas
>
> --
> 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