anchor.diff:                  ;; ELSE: Message for unused channel
                   (warn-nonexistent-channel))))))))
   
  -(defun handle-command (async-conn in-fd)
  -  (sb-alien:with-alien ((buf (sb-alien:array sb-alien:int 1)))
  -    (let* ((size (/ (sb-alien:alien-size sb-alien:int) 8))
  -           (result (sb-posix:read in-fd (sb-alien:addr buf) size)))
  -      (unless (= result size)
  -        (error "Unable to read from pipe"))
  -      (let ((index (sb-alien:deref buf 0)))
  -        (let ((cmd (bordeaux-threads:with-lock-held ((async-connection/lock async-conn))
  -                     (with-accessors ((requests async-connection/requests)) async-conn
  -                       (let ((cmd (assoc index requests)))
  -                         (unless cmd
  -                           (error "Attempt to get missing command index: ~s" index))
  -                         (setf requests (delete (car cmd) requests :key #'car))
  -                         (cdr cmd))))))
  -          (let ((result (funcall (first cmd))))
  -            (funcall (second cmd) result)))))))
  -
  -(defun run-sync-loop (async-conn in-fd)
  -  (let ((socket-fd (cl-rabbit::get-sockfd (async-connection/connection async-conn))))
  +(defun handle-command (async-conn)
  +  (let ((in-fd (async-connection/cmd-fd-reader async-conn)))
  +    (sb-alien:with-alien ((buf (sb-alien:array sb-alien:int 1)))
  +      (let* ((size (/ (sb-alien:alien-size sb-alien:int) 8))
  +             (result (sb-posix:read in-fd (sb-alien:addr buf) size)))
  +        (unless (= result size)
  +          (error "Unable to read from pipe"))
  +        (let ((index (sb-alien:deref buf 0)))
  +          (let ((cmd (bordeaux-threads:with-lock-held ((async-connection/lock async-conn))
  +                       (with-accessors ((requests async-connection/requests)) async-conn
  +                         (let ((cmd (assoc index requests)))
  +                           (unless cmd
  +                             (error "Attempt to get missing command index: ~s" index))
  +                           (setf requests (delete (car cmd) requests :key #'car))
  +                           (cdr cmd))))))
  +            (let ((result (funcall (first cmd))))
  +              (funcall (second cmd) result))))))))
  +
  +(defun wait-select (async-conn)
  +  (let* ((conn (async-connection/connection async-conn))
  +         (socket-fd (cl-rabbit::get-sockfd conn))
  +         (in-fd (async-connection/cmd-fd-reader async-conn)))
       (sb-alien:with-alien ((rfds (sb-alien:struct sb-unix:fd-set)))
         (sb-unix:fd-zero rfds)
  -      (sb-unix:fd-set socket-fd rfds)
  -      (sb-unix:fd-set in-fd rfds)
  +      (locally
  +          (declare (optimize (debug 3) (safety 3) (speed 0)))
  +        (sb-unix:fd-set socket-fd rfds)
  +        (sb-unix:fd-set in-fd rfds))
         (multiple-value-bind (count err)
             (sb-unix:unix-fast-select (1+ (max socket-fd in-fd)) (sb-alien:addr rfds) nil nil 10 0)
           (if count
               (progn
                 (when (sb-unix:fd-isset in-fd rfds)
  -                (handle-command async-conn in-fd))
  +                (handle-command async-conn))
                 (when (sb-unix:fd-isset socket-fd rfds)
                   (wait-for-frame async-conn)))
               ;; ELSE: An error occurred in the call
               (unless (= err sb-unix:eintr)
  -              (error "Error: ~s" err)))))
  -    (log:info "Sync loop for fd ~a finished" socket-fd)))
  +              (error "Error: ~s" err)))))))
  +
  +(defun run-sync-loop (async-conn)
  +  (let ((conn (async-connection/connection async-conn)))
  +    (loop
  +       if (or (cl-rabbit::data-in-buffer conn)
  +              (cl-rabbit::frames-enqueued conn))
  +       do (wait-for-frame async-conn)
  +       else do (wait-select async-conn))))
   
   (defun run-in-sync-thread (async-conn fn)
     (let* ((h (make-transfer-handler))
  
positive.code:                       :accessor async-channel/message-callbacks)
     (close-callbacks   :type list
                        :initform nil
                        :accessor async-channel/close-callbacks)))
  
  (defclass async-connection ()
    ((connection    :type cl-rabbit::connection
  
negative.code: (in-package :cl-rabbit-async)
  
  (declaim (optimize (safety 3) (debug 3) (speed 0)))
  
  (defclass async-channel ()
    ((connection        :type async-connection
  