]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/line-cursor-mode.rb
Merge branch 'master' into next
[sup] / lib / sup / modes / line-cursor-mode.rb
index 0b1fd1de5418cf2c533590e4dfcc2836cb705551..c7c6b9a73b00dfa0fbfd5836fc20fb19e69a8930 100644 (file)
@@ -15,11 +15,22 @@ class LineCursorMode < ScrollMode
   def initialize opts={}
     @cursor_top = @curpos = opts.delete(:skip_top_rows) || 0
     @load_more_callbacks = []
-    @load_more_callbacks_m = Mutex.new
-    @load_more_callbacks_active = false
+    @load_more_q = Queue.new
+    @load_more_thread = ::Thread.new do
+      while true
+        e = @load_more_q.pop
+        @load_more_callbacks.each { |c| c.call e }
+      end
+    end
+
     super opts
   end
 
+  def cleanup
+    @load_more_thread.kill
+    super
+  end
+
   def draw
     super
     set_status
@@ -163,21 +174,8 @@ private
   end
 
   def call_load_more_callbacks size
-    go = 
-      @load_more_callbacks_m.synchronize do
-        if @load_more_callbacks_active
-          false
-        else
-          @load_more_callbacks_active = true
-        end
-    end
-
-    return unless go
-
-    @load_more_callbacks.each { |c| c.call size }
-    @load_more_callbacks_active = false
-  end    
-
+    @load_more_q.push size
+  end
 end
 
 end