Closed PuercoPop closed 8 years ago
I see the problem. with-query
uses unwind-protect
to disconnect the socket when (progn ,@body)
finishes. This is fine in synchronous code, but in our case, the control is returned immediately from the (progn ...)
after hitting the first async operation, which in turn then closes the socket before the results can even come back, and causing the event loop to exit prematurely since there are no events left to process.
Try this:
(defmacro with-db ((socket-name &key (host *host*) (port *port*))
&body body)
"Run the BODY with a socket bound to SOCKET-NAME "
`(alet ((,socket-name (connect ,host ,port)))
(finally (progn ,@body)
(disconnect ,socket-name))))
I'm at work and haven't had a chance to test this, but I think it's what you want.
finally
is the blackbird promise version of unwind-protect
. No matter what happens inside of the body, the disconnect
call will be made at the end of the promise chain returned by the body.
Thanks that does it.
Oi, I'm unsure if this is a bug, I'm misunderstanding how promises are supposed to work or making a simple mistake.
When writing some convenience macros for when working with rethinkdb the &body of both macros as illustrated by the code below. Any pointers as to what could be going wrong?
P.D. Happy Holidays and thanks for cl-async, wookie and cl-rethinkdb!