Class: RightAMQP::HABrokerClient::CountedDeferrable

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/right_amqp/ha_client/ha_broker_client.rb

Overview

Helper for deferring block execution until specified number of actions have completed or timeout occurs

Instance Method Summary collapse

Constructor Details

#initialize(count, timeout = nil) ⇒ CountedDeferrable

Defer action until completion count reached or timeout occurs

Parameter

count(Integer)

Number of completions required for action

timeout(Integer|nil)

Number of seconds to wait for all completions and if

reached, proceed with action; nil means no timing


1127
1128
1129
1130
# File 'lib/right_amqp/ha_client/ha_broker_client.rb', line 1127

def initialize(count, timeout = nil)
  @timer = EM::Timer.new(timeout) { succeed } if timeout
  @count = count
end

Instance Method Details

#completed_oneObject

Completed one part of task

Return

true

Always return true



1136
1137
1138
1139
1140
1141
1142
# File 'lib/right_amqp/ha_client/ha_broker_client.rb', line 1136

def completed_one
  if (@count -= 1) == 0
    @timer.cancel if @timer
    succeed
  end
  true
end