YUKI Hiroshi
null+****@clear*****
Tue Apr 14 20:49:05 JST 2015
YUKI Hiroshi 2015-04-14 20:49:05 +0900 (Tue, 14 Apr 2015) New Revision: d07a8e8eec624cb21815efecbd5132ced172d41a https://github.com/droonga/droonga-client-ruby/commit/d07a8e8eec624cb21815efecbd5132ced172d41a Message: Accept "max_messages" option for subscriptions Modified files: lib/droonga/client/connection/droonga-protocol/thread.rb Modified: lib/droonga/client/connection/droonga-protocol/thread.rb (+15 -1) =================================================================== --- lib/droonga/client/connection/droonga-protocol/thread.rb 2015-04-14 20:40:21 +0900 (7764ea7) +++ lib/droonga/client/connection/droonga-protocol/thread.rb 2015-04-14 20:49:05 +0900 (e927187) @@ -81,16 +81,23 @@ module Droonga send(message, options) subscription_timeout = options[:subscription_timeout] + max_messages = options[:max_messages] start = Time.now receive_options = { :timeout => options[:timeout] || DEFAULT_TIMEOUT_SECONDS, } + n_messages = 0 sync = block.nil? if sync Enumerator.new do |yielder| loop do receiver.receive(receive_options) do |object| yielder << object + n_messages += 1 + end + if max_messages and + n_messages >= max_messages + break end if subscription_timeout elapsed_seconds = Time.now - start @@ -103,7 +110,14 @@ module Droonga thread = ::Thread.new do begin loop do - receiver.receive(receive_options, &block) + receiver.receive(receive_options) do |message| + block.call(message) + n_messages += 1 + end + if max_messages and + n_messages >= max_messages + break + end if subscription_timeout elapsed_seconds = Time.now - start break if elapsed_seconds >= subscription_timeout -------------- next part -------------- HTML����������������������������...Download