 Otherwise, set an idle-timer to call the handler again"
   (lean-server-cancel-retry-timer)
   (when (eq major-mode 'lean-mode)
-    (let* ((cont   (lean-server-async-task-queue-peek-front))
-           (result (lean-server-check-and-process-buffer-with-cont cont)))
+    (let* ((front-item (lean-server-async-task-queue-peek-front))
+           (cont       (car front-item))
+           (cmd-type   (cdr front-item))
+           (result     (lean-server-check-and-process-buffer-with-cont cont
+                                                                       cmd-type)))
       (pcase result
         (`(PROCESSED ,ret)
          (lean-server-async-task-queue-pop-front)

  (lean-server-debug "send-cmd-async: queue len = %d" (lean-server-async-task-queue-len))
  (lean-server-send-cmd cmd)
  (when cont
    (lean-server-async-task-queue-push-back cont)
    (lean-server-debug "send-cmd-async: added to %s the queue, queue size = %d"
                       (lean-cmd-type cmd)
                       (lean-server-async-task-queue-len))

    (process-send-string proc string-to-send)
    (lean-server-after-send-cmd cmd)))

(defun lean-server-process-message-with-cont (body type cont cmd-type)
  "Process the message from lean-server and call continuation"
  (lean-server-debug "process-message-with-cont: type = %S, cmd-type = %S"
                     type cmd-type)
  (lean-server-debug "process-message-with-cont: body\n-----\n%s\n-----\n" body)
  (cl-case type
    (INFO
     (lean-server-debug "Process: INFO")
