]> git.cworth.org Git - sup/commitdiff
make ThreadIndexMode#save optionally threaded
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 25 Mar 2009 12:33:45 +0000 (05:33 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 25 Mar 2009 12:35:28 +0000 (05:35 -0700)
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.

lib/sup/modes/thread-index-mode.rb

index a2f19265cc746f90e2a2a31f494802918c4edd5d..6616601d363580dfd440d6c4da9f6fad9b61e077 100644 (file)
@@ -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