sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit fbca3b3df0a6fcc64dfafab571b9d915b15b41a2
parent 6578c2141763fcf05f63c42eab0908123ffcce3f
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Wed, 25 Mar 2009 05:33:45 -0700

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.

Diffstat:
M lib/sup/modes/thread-index-mode.rb | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git 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