[hunchentoot-devel] Displaying partial output from the handler?

I was wondering if it's possible to create a handler which can output some message to the user browser and then continue with it's own lengthy operation so that a user could see some output? Thank you, Andrew

Andrei Stebakov wrote:
I was wondering if it's possible to create a handler which can output some message to the user browser and then continue with it's own lengthy operation so that a user could see some output?
Yes it's possible, but you cannot use the "return value as document" paradigm anymore, you need to write to the stream directly. Which means you might have some trouble with HTML abstraction tools such as CL-WHO. This works for me: (define-easy-handler (test :uri "/") () (let ((*standard-output* (send-headers))) (format t "<html><head><title>Progressive output</title></head><body>") (dolist (s '("Respect" "to" "the" "man" "in" "the" "icecream" "van!")) (format t "~A<br/>" s) (force-output) (sleep 1)) (format t "<p>Over and out</p></body></html>"))) Although, if the operation is very lengthy (say, more than a minute) you should consider an anyncronous approach: a separate working thread plus client-side page refreshes (or AJAX or an iframe) for status polling. Tobia

Scribit Tobia dies 26/03/2007 hora 21:51:
Although, if the operation is very lengthy (say, more than a minute) you should consider an anyncronous approach: a separate working thread plus client-side page refreshes (or AJAX or an iframe) for status polling.
AJAX is maybe a bit overkill here. Many sites just show an intermediate page with an immediate refresh to goes to the URL of the lengthy computation. As all browsers won't redraw anything before they get data, you can then use the "data as return value" paradigm for both handlers, the intermediate page and the lengthy computation. Alternatively, Pierre -- nowhere.man@levallois.eu.org OpenPGP 0xD9D50D8A

Pierre, I am not sure I understood you. Could you give some example of what you described? Thank you, Andrew On 3/26/07, Pierre THIERRY <nowhere.man@levallois.eu.org> wrote:
Scribit Tobia dies 26/03/2007 hora 21:51:
Although, if the operation is very lengthy (say, more than a minute) you should consider an anyncronous approach: a separate working thread plus client-side page refreshes (or AJAX or an iframe) for status polling.
AJAX is maybe a bit overkill here. Many sites just show an intermediate page with an immediate refresh to goes to the URL of the lengthy computation.
As all browsers won't redraw anything before they get data, you can then use the "data as return value" paradigm for both handlers, the intermediate page and the lengthy computation.
Alternatively, Pierre -- nowhere.man@levallois.eu.org OpenPGP 0xD9D50D8A
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGCIrKxe13INnVDYoRAtmwAJ4uBw2+ZpHfaOl/3YiXQogPYBX0qwCg5Qjn sEoOgEFuXGpz1pI5gkYjcN8= =GK2r -----END PGP SIGNATURE-----
_______________________________________________ tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel

Scribit Andrei Stebakov dies 27/03/2007 hora 10:36:
Pierre, I am not sure I understood you. Could you give some example of what you described?
Sure, here is a file with a complete toy example. Just load the file and go to the following URI: http://localhost:8888/step1 After approximately 8 seconds, your browser should show you a second page, located at: http://localhost:8888/step2 In the meantime, most browsers should leave the first page visible. I'm confident this works on most mainstream browsers because the french national railroad company uses this trick on its online store (that's where I learned it, by the way, I seem to remember). I successfully tested this example under SBCL 1.0.0.0 with Linux and both Firefox and Konqueror. Visually, Pierre -- nowhere.man@levallois.eu.org OpenPGP 0xD9D50D8A
participants (3)
-
Andrei Stebakov
-
Pierre THIERRY
-
Tobia