feat(emacs/lean-server.el): lean-server-consume-all-async-tasks restart lean-server if necessary
related issue: #263
This commit is contained in:
parent
80e3da0526
commit
1829e64a76
2 changed files with 35 additions and 19 deletions
|
@ -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))
|
||||
(while lean-global-async-task-queue
|
||||
(accept-process-output (lean-server-get-process) 0 50 t)
|
||||
(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-debug "lean-server-consume-all-sync-tasks: processed. queue size = %d"
|
||||
(lean-server-async-task-queue-len)))
|
||||
(`(NOTREADY)
|
||||
(lean-debug "lean-server-consume-all-sync-tasks: not ready. queue size = %d"
|
||||
(lean-server-async-task-queue-len)))
|
||||
(t
|
||||
(lean-server-async-task-queue-pop-front)
|
||||
(lean-debug "lean-server-consume-all-sync-tasks: either error or quit happend. queue size = %d"
|
||||
(lean-server-async-task-queue-len))))))
|
||||
(lean-debug "lean-server-consume-all-async-tasks: over. queue size = %d"
|
||||
(lean-server-async-task-queue-len)))
|
||||
(let ((kill-timer (run-at-time lean-time-to-restart-server nil
|
||||
'(lambda () (lean-server-restart-process)))))
|
||||
(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-debug "lean-server-consume-all-sync-tasks: processed. queue size = %d"
|
||||
(lean-server-async-task-queue-len)))
|
||||
(`(NOTREADY)
|
||||
(lean-debug "lean-server-consume-all-sync-tasks: not ready. queue size = %d"
|
||||
(lean-server-async-task-queue-len)))
|
||||
(t
|
||||
(lean-server-async-task-queue-pop-front)
|
||||
(lean-debug "lean-server-consume-all-sync-tasks: either error or quit happend. queue size = %d"
|
||||
(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)
|
||||
"Send cmd to lean-server (sync)."
|
||||
|
@ -600,4 +603,13 @@ Otherwise, set an idle-timer to call the handler again"
|
|||
(when (buffer-modified-p)
|
||||
(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)
|
||||
|
|
|
@ -151,4 +151,8 @@ false (nil)."
|
|||
"Disable this if we don't need to keep track of the changes. A usage
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue