[Groonga-commit] droonga/droonga-client-ruby at acf5f6a [master] Support timeout of subscriptions

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Apr 14 19:56:36 JST 2015


YUKI Hiroshi	2015-04-14 19:56:36 +0900 (Tue, 14 Apr 2015)

  New Revision: acf5f6adadab976581c9d1a26102eb8a4c99e88a
  https://github.com/droonga/droonga-client-ruby/commit/acf5f6adadab976581c9d1a26102eb8a4c99e88a

  Message:
    Support timeout of subscriptions

  Modified files:
    lib/droonga/client/connection/droonga-protocol/coolio.rb

  Modified: lib/droonga/client/connection/droonga-protocol/coolio.rb (+17 -2)
===================================================================
--- lib/droonga/client/connection/droonga-protocol/coolio.rb    2015-04-14 16:36:11 +0900 (254160f)
+++ lib/droonga/client/connection/droonga-protocol/coolio.rb    2015-04-14 19:56:36 +0900 (84acc0c)
@@ -37,11 +37,22 @@ module Droonga
           end
 
           class InfiniteRequest
-            def initialize(loop)
+            attr_writer :on_timeout
+
+            def initialize(loop, options={})
               @loop = loop
+              @timeout_seconds = options[:timeout_seconds]
             end
 
             def wait
+              if @timeout_seconds
+                @timer = Coolio::TimerWatcher.new(@timeout_seconds)
+                @timer.on_timer do
+                  @timer.detach
+                  @on_timeout.call if @on_timeout
+                end
+                @loop.attach(@timer)
+              end
               @loop.run
             end
           end
@@ -217,7 +228,11 @@ module Droonga
             end
 
             id = message["id"]
-            request = InfiniteRequest.new(@loop)
+            request = InfiniteRequest.new(@loop,
+                                          :timeout_seconds => options[:timeout_seconds])
+            request.on_timeout = lambda do
+              @receiver.unregister(id)
+            end
             sync = block.nil?
             if sync
               yielder = nil
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index