From: William Morgan Date: Wed, 25 Mar 2009 12:33:45 +0000 (-0700) Subject: make ThreadIndexMode#save optionally threaded X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=fbca3b3df0a6fcc64dfafab571b9d915b15b41a2;p=sup make ThreadIndexMode#save optionally threaded The call to #save during #cleanup needs to block because this is where state gets saved immediately before exit. Other calls to #save, e.g. those triggered by "$", can be backgrounded. --- diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index a2f1926..6616601 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -387,18 +387,24 @@ EOS BufferManager.flash "#{threads.size.pluralize 'Thread'} killed." end - def save - Redwood::reporting_thread("saving thread") do - @save_thread_mutex.synchronize do - BufferManager.say("Saving contacts...") { ContactManager.instance.save } - dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } } - return if dirty_threads.empty? - - BufferManager.say("Saving threads...") do |say_id| - dirty_threads.each_with_index do |t, i| - BufferManager.say "Saving modified thread #{i + 1} of #{dirty_threads.length}...", say_id - t.save Index - end + def save background=true + if background + Redwood::reporting_thread("saving thread") { actually_save } + else + actually_save + end + end + + def actually_save + @save_thread_mutex.synchronize do + BufferManager.say("Saving contacts...") { ContactManager.instance.save } + dirty_threads = @mutex.synchronize { (@threads + @hidden_threads.keys).select { |t| t.dirty? } } + next if dirty_threads.empty? + + BufferManager.say("Saving threads...") do |say_id| + dirty_threads.each_with_index do |t, i| + BufferManager.say "Saving modified thread #{i + 1} of #{dirty_threads.length}...", say_id + t.save Index end end end @@ -413,7 +419,7 @@ EOS sleep 0.1 # TODO: necessary? BufferManager.erase_flash end - save + save false super end