lib/sup/poll.rb in sup-0.0.2 vs lib/sup/poll.rb in sup-0.0.3

- old
+ new

@@ -10,17 +10,10 @@ def initialize @polling = false @last_poll = nil self.class.i_am_the_instance self - - Redwood::reporting_thread do - while true - sleep DELAY / 2 - poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY - end - end end def buffer BufferManager.spawn_unless_exists("<poll for new messages>", :hidden => true) do PollMode.new @@ -36,10 +29,19 @@ BufferManager.flash "No new messages." end [num, numi] end + def start_thread + Redwood::reporting_thread do + while true + sleep DELAY / 2 + poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY + end + end + end + def do_poll return [0, 0] if @polling @polling = true found = {} total_num = 0 @@ -52,11 +54,11 @@ start_offset = nil num = 0 num_inbox = 0 source.each do |offset, labels| start_offset ||= offset - yield " Found message at #{offset} with labels #{labels * ', '}" + yield "Found message at #{offset} with labels #{labels * ', '}" begin m = Redwood::Message.new :source => source, :source_info => offset, :labels => labels if found[m.id] yield "Skipping duplicate message #{m.id}" @@ -69,10 +71,10 @@ UpdateManager.relay :add, m num += 1 total_num += 1 total_numi += 1 if m.labels.include? :inbox end - rescue Redwood::MessageFormatError => e + rescue SourceError, MessageFormatError => e yield "Ignoring erroneous message at #{source}##{offset}: #{e.message}" end if num % 1000 == 0 && num > 0 elapsed = Time.now - start