I think it is pretty simple. ``` (define (make-periodically-updating-value compute1) (define the-data (box (compute1))) (define the-updater-t (thread (λ () (let loop () (set-box! the-data (compute1)) (sleep interval) (loop))))) (λ () (unbox the-data)))
(define get-the-data/cache (make-periodically-updating-value get-the-data/for-realsies)) ``` Box mutation is atomic, so you don't need locks or anything. It would be more complicated if you want to not compute it initially. -- Jay McCarthy Associate Professor @ CS @ UMass Lowell http://jeapostrophe.github.io Vincit qui se vincit. On Tue, Aug 13, 2019 at 7:53 PM Wayne Harris <wharr...@protonmail.com> wrote: > > Is there an example somewhere showing how this could be done? My wish is to > have one thing (a thread or something) periodically updating data (say every > 30 minutes) and all servlets handling http connections reading. It is > perfectly fine for me if while something writes the data, everything else is > blocked waiting. > > Having said that, I think this might be getting out of my league. (I'm > reading about events in the hope I can find a way.) I have very basic > understanding of Racket's primitives; never done anything involving threads > or any kind of concurrency. If there's no trivial way to do that, I'll leave > it for some other future project. > > On Tuesday, August 13, 2019 5:07 PM, Jay McCarthy <jay.mccar...@gmail.com> > wrote: > > > Hi Wayne, > > > > Your `in-memory-database` is a parameter. Parameters are > > thread-specific storage [1]. Every request in the web-server is > > handled by a different thread, so I think this will not work how you > > think it should. > > > > Jay > > > > 1. > > https://docs.racket-lang.org/reference/parameters.html#(form._((lib._racket%2Fprivate%2Fmore-scheme..rkt)._parameterize)) > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAJYbDa%3D4vGyGVNjGBTMeNW30hjWK2UMvA8-8ynd5CLpkFMYnug%40mail.gmail.com.