From 665f362ce1a0a22bc10d3bbe95d5a8adec2df653 Mon Sep 17 00:00:00 2001
From: Niten <niten@fudo.org>
Date: Tue, 24 Nov 2020 11:26:20 -0800
Subject: [PATCH] Added back with-backplane

---
 backplane-server.lisp | 15 ++++++++++-----
 package.lisp          |  3 ++-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/backplane-server.lisp b/backplane-server.lisp
index f277785..7b69e63 100644
--- a/backplane-server.lisp
+++ b/backplane-server.lisp
@@ -127,8 +127,13 @@
                           :mechanism :sasl-plain)
                backplane))))
 
-;; (defmacro with-backplane (backplane &rest ops)
-;;   (let ((bp-sym (gensym)))
-;;     `(let ((,bp-sym ,backplane))
-;;        (unwind-protect (progn ,@ops)
-;;          (cl-xmpp:disconnect ,bp-sym)))))
+(defmacro with-backplane (bp-clause &rest ops)
+  (when (or (not (listp bp-clause))
+            (not (= 2 (length bp-clause)))
+            (not (symbolp (car bp-clause))))
+    (error "bad backplane clause"))
+  (let ((bp-name (car bp-clause)))
+    `(let ((,bp-name ,(cadr bp-clause)))
+       (unwind-protect
+            (progn ,@ops)
+         (cl-xmpp:disconnect ,bp-name)))))
diff --git a/package.lisp b/package.lisp
index 5eb585b..6f9ab62 100644
--- a/package.lisp
+++ b/package.lisp
@@ -17,4 +17,5 @@
                 #:error-p
                 #:parse-message
                 #:handle-message
-                #:backplane-connect))
+                #:backplane-connect
+                #:with-backplane))