Question (or idea?) about wrap-stateful-session

22 views
Skip to first unread message

Don Jackson

unread,
Aug 4, 2011, 2:44:30 AM8/4/11
to sandbar...@googlegroups.com

This is a slightly revised version of  the question I just posted to the ring mailing list, but thought I'd also ask here….


For a web app I am developing, there are some things I need to compute for a user that take "a long time", e.g. many seconds.

If I begin these computations as a direct result of a user request, the user will need to wait for the response,  and I'd prefer to do better, if possible.

To the extent that I can avoid needing the result(s) of those lengthy computations for the first page(s) the user accesses, it seems like it would behoove me
to begin these long tasks in the background (via a Clojure future?), upon first access.  It may very well take the user several seconds (or longer)  to get
to the part of the app that needs these results, and if I'm lucky, they will already be done when the user needs them, or worst case, at least I got a head start on this
computation, and now the user will just need to wait a bit longer for it to finish.

So, I'm thinking I'd like to store the results of all this "eager" computation in the user's session.

Sandbar's wrap-stateful-session (and Ring's wrap-session)  look pretty useful for all this.

My question:  Is there a way to provide a (callback) function to wrap-stateful-session that would get executed when a new session is created?
If so, how?

If not, might this be a good addition to wrap-session-stateful/wrap-session?

Perhaps a new option :new-session-callback whose value is obviously the function to be called.
Presumably the callback function would be provided access to the newly created session, so it can read and update it.

Is this a decent, or terrible idea?  :-)

If not so bad, where best to add the call of the provided callback function?  Is this something that would need to happen to 
Ring's wrap-session or could this be done in Sandbar's wrap-stateful-session?

Advice, pointers, feedback welcome.

Don





Reply all
Reply to author
Forward
0 new messages