[Haskell-cafe] Happstack events and web page refreshing

Bas van Dijk v.dijk.bas at gmail.com
Wed Jan 19 14:21:39 CET 2011


On 17 January 2011 21:50, Jeremy Shaw <jeremy at n-heptane.com> wrote:
>
> On Jan 17, 2011, at 2:19 PM, Corentin Dupont wrote:
>
> Indeed, I tried with <META HTTP-EQUIV="Refresh" CONTENT="n"> ?
> and it's unusable.
> It make blink the page, ungrey the "stop" button for a second and make the
> fields loose the focus
> so it's impossible to type in.
>
> I'll try with XMLHTTPRequest.
>
>
> Right. Using the jQuery library should make it easier to do ajax requests
> and modify the DOM on the fly,
> http://jquery.com/
> - jeremy
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

A nice variation of polling is "long polling":

http://en.wikipedia.org/wiki/Push_technology#Long_polling

This can easily be accomplished in Haskell by having an MVar per
session. Initially an empty MVar is created per new session. When a
client makes a request, the server thread that handles the request
takes the MVar belonging to the session. This thread will block until
the MVar is filled. When the server has an update it will fill all the
MVars. This causes all the blocked threads to continue with sending a
response to the client notifying it about the update.

Like Jeremy said it's a good idea to make these update requests asynchronous.

Regards,

Bas



More information about the Haskell-Cafe mailing list