Hi Ivan et al,

I have managed to re-read the string every 15 seconds, the problem is
that the slurp reads stale data. It returns always the same string,
even though I can see in my browser that it has changed. This also
happens when I just do the slurp in the REPL. Apologies for not making
this clearer in the original post.

Thomas

On Jun 10, 9:03 am, Ivan Koblik <[email protected]> wrote:
> 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/[email protected]/msg00136.html
>
> Cheers,
> Ivan.
>
> On 6 June 2011 14:51, Thomas <[email protected]> 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 [email protected]
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > [email protected]
> > 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 [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to