Sleep between retrying asynchronous notmuch commands and check for
notmuch-process before firing off a new one

If the db is locked when notmuch tries to write to it, an error is
reported to the client (in this case, notmuch.el).  Instead of
accepting that error, wait a small amount of time and then try again.

Also, don't start multiple asynchronous processes.
---
 notmuch.el |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 7fc63e9..31e89b9 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -1402,9 +1402,14 @@ args is a list of arguments to notmuch.  ex: (\"tag\" 
\"+list\"

 Calls to notmuch are queued and called asynchronously."
   (setq notmuch-asynch-queue (append notmuch-asynch-queue (list args)))
-  (when (= (length notmuch-asynch-queue) 1)
+  (when (and (= (length notmuch-asynch-queue) 1)
+            (not (get-process "notmuch-process")))
     (apply 'notmuch-call-notmuch-process-asynch (pop notmuch-asynch-queue))))
-  
+
+(defun notmuch-asynch-sleep-sentinel (process event)
+  "After we sleep, try a command from the notmuch queue"
+  (apply 'notmuch-call-notmuch-process-asynch (pop notmuch-asynch-queue)))
+
 (defun notmuch-call-notmuch-process-asynch-sentinel (process event)
   "Handle the exit of a notmuch asynch process.

@@ -1416,11 +1421,16 @@ command, try it again."
     (if (= (process-exit-status process) 0)
        (kill-buffer (buffer-name (process-buffer process)))
        (if (search-forward "Unable to acquire database write lock" nil t)
-           (apply 'notmuch-call-notmuch-process-asynch (cdr (process-command 
process)))
+           (progn
+             (push (cdr (process-command process)) notmuch-asynch-queue)
+             (set-process-sentinel 
+              (start-process "notmuch-sleep" nil "sleep" "3")
+              'notmuch-asynch-sleep-sentinel))
            (error (format "%s: %s" (join-string-list (process-command process))
                           (buffer-string))))))
   (apply 'notmuch-call-notmuch-process-asynch (pop notmuch-asynch-queue)))

+
 (defun notmuch-call-notmuch-process (&rest args)
   "Synchronously invoke \"notmuch\" with the given list of arguments.

-- 
1.6.3.3

Reply via email to