diff options
author | Teddy Wing | 2021-02-01 00:05:26 +0100 |
---|---|---|
committer | Teddy Wing | 2021-02-01 00:05:26 +0100 |
commit | 6142d3676a576d35fed0dab7a7cd6b05487aec7f (patch) | |
tree | 954236294e46d5c2cde42dcad315aed7772524ed /l/src/macro.lisp | |
parent | 890089f73cac5d58573d7d7e3981b5c8a3c0e167 (diff) | |
download | extreload-6142d3676a576d35fed0dab7a7cd6b05487aec7f.tar.bz2 |
main: Ensure WebSocket connection is always closed
Create a new `with-websocket-connection` decorator that starts and
closes a WebSocket connection to the given `client` around the body
forms.
Thanks to Practical Common Lisp's "The Special Operators" chapter
(http://www.gigamonkeys.com/book/the-special-operators.html#unwinding-the-stack)
for introducing me to `unwind-protect`.
Couldn't figure out how to get the new macro to auto-indent properly
with Vlime, so ended up manually indenting it.
Diffstat (limited to 'l/src/macro.lisp')
-rw-r--r-- | l/src/macro.lisp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/l/src/macro.lisp b/l/src/macro.lisp index 4d69294..283cf9f 100644 --- a/l/src/macro.lisp +++ b/l/src/macro.lisp @@ -2,3 +2,9 @@ (defmacro filter (predicate list-form) `(remove-if-not ,predicate ,list-form)) + +(defmacro with-websocket-connection ((client) &body body) + `(progn + (wsd:start-connection ,client) + (unwind-protect (progn ,@body) + (wsd:close-connection ,client)))) |