]> git.cworth.org Git - sup/commitdiff
unified reporting of thread exceptions
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 10 Dec 2006 19:41:43 +0000 (19:41 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 10 Dec 2006 19:41:43 +0000 (19:41 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@71 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup
lib/sup/modes/label-list-mode.rb
lib/sup/modes/thread-index-mode.rb
lib/sup/poll.rb

diff --git a/bin/sup b/bin/sup
index 003e8f5b7cc553b3ef8080d94c0f1339dd61a723..05677cacb9ea1f21358e3d3306915aa2c1dc7a22 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -7,6 +7,17 @@ require "sup"
 module Redwood
 
 $exception = nil
+def reporting_thread
+  ::Thread.new do
+    begin
+      yield
+    rescue Exception => e
+      $exception ||= e
+      raise
+    end
+  end
+end
+module_function :reporting_thread
 
 global_keymap = Keymap.new do |k|
   k.add :quit, "Quit Redwood", 'q'
@@ -109,7 +120,7 @@ begin
   bm.draw_screen
   imode.load_more_threads ibuf.content_height
 
-  ::Thread.new { sleep 3; PollManager.poll }
+  reporting_thread { sleep 3; PollManager.poll }
 
   until $exception
     bm.draw_screen
index 80f584ccaef295ffe7d68a6499b8c6ab0080168d..60f4f235065a6b6c13df6a757ab73a7ff0a2042e 100644 (file)
@@ -18,7 +18,7 @@ class LabelListMode < LineCursorMode
   def load; regen_text; end
 
   def load_in_background
-    ::Thread.new do
+    Redwood::reporting_thread do
       regen_text do |i|
         if i % 10 == 0
           buffer.mark_dirty
index 923347b129173641aa9ca11f1d8c04a9623697af..5845ea2306db84d4e987f88611e58402ca0f9000 100644 (file)
@@ -265,14 +265,9 @@ class ThreadIndexMode < LineCursorMode
 
   def load_n_threads_background n=LOAD_MORE_THREAD_NUM, opts={}
     return if @load_thread
-    @load_thread = ::Thread.new do 
-      begin
-        num = load_n_threads n, opts
-        opts[:when_done].call(num) if opts[:when_done]
-      rescue Exception => e
-        $exception ||= e
-        raise
-      end
+    @load_thread = Redwood::reporting_thread do 
+      num = load_n_threads n, opts
+      opts[:when_done].call(num) if opts[:when_done]
       @load_thread = nil
     end
   end
index 2afe66eadec0f7073eb9bacadfb8d534c372a072..e36615464b9c00a838242e8aa053f66b58be55dd 100644 (file)
@@ -13,12 +13,10 @@ class PollManager
     
     self.class.i_am_the_instance self
 
-    ::Thread.new do
+    Redwood::reporting_thread do
       while true
         sleep DELAY / 2
-        if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
-          poll
-        end
+        poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
       end
     end
   end
@@ -46,6 +44,7 @@ class PollManager
     found = {}
     total_num = 0
     total_numi = 0
+
     Index.usual_sources.each do |source|
       next if source.done?
       yield "Loading from #{source}... "
@@ -60,7 +59,7 @@ class PollManager
           m = Redwood::Message.new :source => source, :source_info => offset,
                                    :labels => labels
           if found[m.id]
-            yield "Skipping duplicate message #{m.id} (source total #{source.total})"
+            yield "Skipping duplicate message #{m.id}"
             next
           else
             found[m.id] = true
@@ -79,7 +78,7 @@ class PollManager
         if num % 1000 == 0 && num > 0
           elapsed = Time.now - start
           pctdone = (offset.to_f - start_offset) / (source.total.to_f - start_offset)
-          remaining = (source.total.to_f - offset.to_f) * (elapsed.to_f / (offset.to_f - start_offset))
+          remaining = (source.end_offset.to_f - offset.to_f) * (elapsed.to_f / (offset.to_f - start_offset))
           yield "## #{num} (#{(pctdone * 100.0)}% done) read; #{elapsed.to_time_s} elapsed; est. #{remaining.to_time_s} remaining"
         end
       end