Subject: [sup-talk] [PATCH 2/4] Poll for editor status

From: Ramkumar Ramachandra <[email-masked]>
Date: Sat, 10 Apr 2010 16:09:04 +0530

Write a second loop in PollManager to poll and check if the
asynchronously spawned editor has finished. If finished, fire a
callback.

Signed-off-by: Ramkumar Ramachandra <[email-masked]>
---
 lib/sup/poll.rb |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
index 582cd4d..0fabb87 100644
--- a/lib/sup/poll.rb
+++ b/lib/sup/poll.rb
@@ -38,6 +38,13 @@ EOS
     @poll_sources = nil
     @mode = nil
     @should_clear_running_totals = false
+    
+    # For async editing
+    @editor_thread = nil
+    @edit_in_progress = false
+    @editor_file = nil
+    @edit_mtime = nil
+
     clear_running_totals # defines @running_totals
     UpdateManager.register self
   end
@@ -71,6 +78,20 @@ EOS
     [num, numi]
   end
 
+  def poll_editor
+    return if @polling
+    return if not @edit_in_progress
+    @polling = true
+    if @editor_thread.alive?
+      BufferManager.flash "Edit in progress..."
+    else
+      BufferManager.flash "Edit finished!"
+      @edit_in_progress = false
+      ComposeMode.edit_message_callback @editor_file, @editor_mtime
+    end
+    @polling = false
+  end
+
   def poll_unusual
     return if @polling
     @polling = true
@@ -83,8 +104,9 @@ EOS
   def start
     @thread = Redwood::reporting_thread("periodic poll") do
       while true
-        sleep DELAY / 2
+        sleep 1
         poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
+        poll_editor if @last_poll.nil? || (Time.now - @last_poll) >= 2
       end
     end
   end
@@ -192,6 +214,13 @@ EOS
     UpdateManager.relay self, :added, m
   end
 
+  def editor_loop_init pthread, file, mtime
+    @editor_thread = pthread
+    @edit_in_progress = true
+    @editor_file = file
+    @editor_mtime = mtime
+  end
+
   def handle_idle_update sender, idle_since; @should_clear_running_totals = false; end
   def handle_unidle_update sender, idle_since; @should_clear_running_totals = true; clear_running_totals; end
   def clear_running_totals; @running_totals = {:num => 0, :numi => 0, :loaded_labels => Set.new}; end
-- 
1.7.0.4
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk