feat(emacs/lean-server.el): lean-server-consume-all-async-tasks restart lean-server if necessary

related issue: #263
This commit is contained in:
Soonho Kong 2015-07-28 18:10:46 -07:00
parent 80e3da0526
commit 1829e64a76
2 changed files with 35 additions and 19 deletions

View file

@ -432,25 +432,28 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd.
(lean-server-async-task-queue-len)) (lean-server-async-task-queue-len))
(while lean-global-async-task-queue (while lean-global-async-task-queue
(accept-process-output (lean-server-get-process) 0 50 t) (accept-process-output (lean-server-get-process) 0 50 t)
(let* ((front-item (lean-server-async-task-queue-peek-front)) (let ((kill-timer (run-at-time lean-time-to-restart-server nil
(cont (car front-item)) '(lambda () (lean-server-restart-process)))))
(cmd-type (cdr front-item)) (let* ((front-item (lean-server-async-task-queue-peek-front))
(result (lean-server-check-and-process-buffer-with-cont cont (cont (car front-item))
cmd-type))) (cmd-type (cdr front-item))
(pcase result (result (lean-server-check-and-process-buffer-with-cont cont
(`(PROCESSED ,ret) cmd-type)))
(lean-server-async-task-queue-pop-front) (pcase result
(lean-debug "lean-server-consume-all-sync-tasks: processed. queue size = %d" (`(PROCESSED ,ret)
(lean-server-async-task-queue-len))) (lean-server-async-task-queue-pop-front)
(`(NOTREADY) (lean-debug "lean-server-consume-all-sync-tasks: processed. queue size = %d"
(lean-debug "lean-server-consume-all-sync-tasks: not ready. queue size = %d" (lean-server-async-task-queue-len)))
(lean-server-async-task-queue-len))) (`(NOTREADY)
(t (lean-debug "lean-server-consume-all-sync-tasks: not ready. queue size = %d"
(lean-server-async-task-queue-pop-front) (lean-server-async-task-queue-len)))
(lean-debug "lean-server-consume-all-sync-tasks: either error or quit happend. queue size = %d" (t
(lean-server-async-task-queue-len)))))) (lean-server-async-task-queue-pop-front)
(lean-debug "lean-server-consume-all-async-tasks: over. queue size = %d" (lean-debug "lean-server-consume-all-sync-tasks: either error or quit happend. queue size = %d"
(lean-server-async-task-queue-len))) (lean-server-async-task-queue-len)))))
(cancel-timer kill-timer)
(lean-debug "lean-server-consume-all-async-tasks: over. queue size = %d"
(lean-server-async-task-queue-len)))))
(defun lean-server-send-cmd-sync (cmd &optional cont) (defun lean-server-send-cmd-sync (cmd &optional cont)
"Send cmd to lean-server (sync)." "Send cmd to lean-server (sync)."
@ -600,4 +603,13 @@ Otherwise, set an idle-timer to call the handler again"
(when (buffer-modified-p) (when (buffer-modified-p)
(lean-server-send-cmd-async (lean-cmd-sync)))) (lean-server-send-cmd-async (lean-cmd-sync))))
;; Sanity Check
;; ============
;; Compare the current buffer and the copy that lean-server is
;; maintaining.
(defun lean-server-sanity-check-p ()
(interactive)
(lean-server-send-cmd-async (lean-cmd-show) (lambda (msg) msg)))
(provide 'lean-server) (provide 'lean-server)

View file

@ -151,4 +151,8 @@ false (nil)."
"Disable this if we don't need to keep track of the changes. A usage "Disable this if we don't need to keep track of the changes. A usage
is to batch-process .org files to .html files") is to batch-process .org files to .html files")
(defcustom lean-time-to-restart-server 1
"After lean-time-to-kill-server passed, we restart lean-server if
the all jobs in the queue are not process.")
(provide 'lean-settings) (provide 'lean-settings)