PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/src/async.lisp

http://github.com/mtravers/wuwei
Lisp | 55 lines | 18 code | 9 blank | 28 comment | 0 complexity | c1939389f77da039c000d255e84909ab MD5 | raw file
 1(in-package :wu)
 2
 3;;; +=========================================================================+
 4;;; | Copyright (c) 2009, 2010  Mike Travers and CollabRx, Inc                |
 5;;; |                                                                         |
 6;;; | Released under the MIT Open Source License                              |
 7;;; |   http://www.opensource.org/licenses/mit-license.php                    |
 8;;; |                                                                         |
 9;;; | Permission is hereby granted, free of charge, to any person obtaining   |
10;;; | a copy of this software and associated documentation files (the         |
11;;; | "Software"), to deal in the Software without restriction, including     |
12;;; | without limitation the rights to use, copy, modify, merge, publish,     |
13;;; | distribute, sublicense, and/or sell copies of the Software, and to      |
14;;; | permit persons to whom the Software is furnished to do so, subject to   |
15;;; | the following conditions:                                               |
16;;; |                                                                         |
17;;; | The above copyright notice and this permission notice shall be included |
18;;; | in all copies or substantial portions of the Software.                  |
19;;; |                                                                         |
20;;; | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,         |
21;;; | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF      |
22;;; | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  |
23;;; | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY    |
24;;; | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,    |
25;;; | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE       |
26;;; | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                  |
27;;; +=========================================================================+
28
29;;; Author:  Mike Travers
30
31
32(export '(async))
33
34;;; Render a DIV with PRE-TEXT now, and replace it with the results of BODY when that completes.
35;;; Note that the use of continuations replaces a ton of special-purpose machinery.
36
37(defmacro async ((&key (pre-text "waiting...") spinner) &body body)
38  `(let ((%id (gensym "async")))
39     (html
40      ((:div :id %id)
41       (:princ ,pre-text)
42       (when ,spinner
43	 (html (image-tag "spinner.gif"))))
44      ((:script :type "text/javascript")
45       (:princ
46	(remote-function 
47	 (ajax-continuation ()
48	   (render-update
49	     (:update
50	      %id
51	      ,@body)))
52	 :in-function? nil))))))
53
54
55