aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gtwiwtg.lisp9
-rw-r--r--package.lisp1
2 files changed, 10 insertions, 0 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index 83f7cf5..6f0f6f3 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -749,6 +749,15 @@ This is sort of the opposite of INTERSPERSE!."
;;; CONSUMERS
+(defmacro with-generator ((var gen) &body body)
+ "Use this if you absolutely must manually call NEXT and
+HAS-NEXT-P. It will ensure that the generator bound to VAR will be
+stopped and cleaned up properly."
+ `(let ((,var ,gen))
+ (assert (typep ,var 'gtwiwtg::generator!))
+ (unwind-protect (progn ,@body)
+ (stop ,var))))
+
(defmacro for (var-exp gen &body body)
"The basic generator consumer.
diff --git a/package.lisp b/package.lisp
index 9916cf3..061ddb7 100644
--- a/package.lisp
+++ b/package.lisp
@@ -30,6 +30,7 @@
#:truncate!
#:inject!
#:disperse!
+ #:with-generator
#:for
#:fold
#:collect