PageRenderTime 17ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/async.lisp

http://github.com/mtravers/wuwei
Lisp | 53 lines | 46 code | 6 blank | 1 comment | 1 complexity | 2a5686567dd5578839c0980006fc175a MD5 | raw file
 1(in-package :wu)
 2
 3(publish-code)
 4
 5;;; An example of the use of ASYNC.
 6
 7(defun fact (n)
 8  (if (zerop n) 1
 9      (* n (fact (- n 1)))))
10
11(publish :path "/async-demo"
12	 :content-type "text/html"
13	 :function 'async-demo)
14
15(defun async-demo (req ent)
16  (with-session (req ent)
17    (with-http-response-and-body (req ent)
18      (html
19	(:head
20	 (css-includes "wuwei.css")
21	 (javascript-includes "prototype.js" "effects.js" "dragdrop.js"))
22	(let ((continuation 
23	       (ajax-continuation (:keep t :args (n))
24		 (render-update
25		   (:update "answer" "")
26		   (:hide "error_box"))
27		 (let ((n (parse-integer n)))
28		   (assert (> n 0) (n) "Must be positive")
29		   (render-update 
30		     (:update "answer"
31			      (async (:pre-text "Wait for it..." :spinner t)
32				(html (:princ "It's ")
33				      (:princ (log (fact n)))))))))))
34	  (html
35	    (:body
36	     (example-header #.(this-pathname))
37
38	     (:h3 "Async and error handling demo")
39	     (:princ "This demo shows off asynchronous results (with the async macro), error handling, and a few assorted other features.  The checkbox selects between two different error handling styles.")
40	     :p
41	     (checkbox-to-remote "Show errors on page?" 
42				 (ajax-continuation (:args (checked) :keep t)
43				   (setf *ajax-error-box?* (equal checked "true")))
44				 *ajax-error-box?*)
45	     :p
46	     (:princ (format nil "Compute log(n!):  (try an non-integer argument)"))
47	     ((:form :method :post :onsubmit (remote-function continuation :form t))
48	      ((:input :name "n" :value "5000"))
49	      ((:input :type :submit)))
50	     ((:div :id "answer"))
51	     ((:div :id "error_box" :style "display:none;"))
52	     (tracker)
53	     )))))))