Skip to content
Snippets Groups Projects
Commit e0e27098 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

utils: Add 'unwind-protect'.

* src/cuirass/utils.scm (unwind-protect): New macro.
parent 787969c9
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@
object->json-scm
object->json-string
define-enumeration
unwind-protect
non-blocking
essential-task
bytevector-range))
......@@ -67,6 +68,25 @@ value."
((_ symbol) value)
...)))
(define-syntax-rule (unwind-protect body ... conclude)
"Evaluate BODY... and return its result(s), but always evaluate CONCLUDE
before leaving, even if an exception is raised.
This is *not* implemented with 'dynamic-wind' in order to play well with
delimited continuations and fibers."
(let ((conclusion (lambda () conclude)))
(catch #t
(lambda ()
(call-with-values
(lambda ()
body ...)
(lambda results
(conclusion)
(apply values results))))
(lambda args
(conclusion)
(apply throw args)))))
(define (%non-blocking thunk)
(let ((channel (make-channel)))
(call-with-new-thread
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment