anchor.diff:                        (/ (sb-alien:alien-size sb-alien:int) 8)))
       (wait-for-value h)))
   
  +(defmacro with-sync (conn &body body)
  +  `(run-in-sync-thread ,conn (lambda () ,@body)))
  +
   (defun open-channel (async-conn)
  -  (run-in-sync-thread async-conn
  -                      (lambda ()
  -                        (let* ((index (find-free-channel-index async-conn))
  -                               (channel (1+ index)))
  -                          (cl-rabbit:channel-open (async-connection/connection async-conn) channel)
  -                          (log:info "Opened channel: ~s" index)
  -                          (let ((async-channel (make-instance 'async-channel
  -                                                              :connection async-conn
  -                                                              :channel channel)))
  -                            (setf (aref (async-connection/channels async-conn) index) async-channel)
  -                            async-channel)))))
  +  (with-sync async-conn
  +    (let* ((index (find-free-channel-index async-conn))
  +           (channel (1+ index)))
  +      (cl-rabbit:channel-open (async-connection/connection async-conn) channel)
  +      (log:info "Opened channel: ~s" index)
  +      (let ((async-channel (make-instance 'async-channel
  +                                          :connection async-conn
  +                                          :channel channel)))
  +        (setf (aref (async-connection/channels async-conn) index) async-channel)
  +        async-channel))))
  +
  +(defun close-channel (async-channel)
  +  (when (async-channel/close-p async-channel)
  +    (error "Channel is already closed"))
  +  (let ((async-conn (async-channel/connection async-channel)))
  +    (with-sync async-conn
  +      (cl-rabbit:channel-close (async-connection/connection async-conn) (async-channel/channel async-channel))
  +      (setf (async-channel/close-p async-channel) t)
  +      (let ((channels (async-connection/channels async-conn))
  +            (index (1- (async-channel/channel async-channel))))
  +        (assert (not (null (aref channels index))))
  +        (setf (aref channels index) nil))
  +      nil)))
   
   (defun make-async-connection ()
     (let* ((conn (cl-rabbit:new-connection))
  
positive.code:       (trivial-garbage:finalize conn-wrapper
                                  (lambda ()
                                    (log:warn "Reference to RabbitMQ connection object lost. Closing.")
                                    (cl-rabbit:destroy-connection conn)))
        (multiple-value-bind (in-fd out-fd)
            (sb-posix:pipe)
          (setf (async-connection/cmd-fd conn-wrapper) out-fd)
          (bordeaux-threads:make-thread (lambda () (run-sync-loop conn-wrapper in-fd))
                                        :name "RabbitMQ listener")
          conn-wrapper))))
  
  #+nil(defun connect-test ()
    (cl-rabbit:with-connection (conn)
  
negative.code: (in-package :cl-rabbit-async)
  
  (declaim (optimize (safety 3) (debug 3) (speed 0)))
  
  (defclass async-channel ()
    ((connection        :type async-connection
  