class Floss::LogReplicator::IndexWaiter

Public Class Methods

new() click to toggle source
# File lib/floss/log_replicator.rb, line 22
def initialize
  @waiters = []
end

Public Instance Methods

register(peer, index, condition) click to toggle source
# File lib/floss/log_replicator.rb, line 26
def register(peer, index, condition)
  # This class is always used to wait for replication of a log entry, so we're failing fast here:
  # Every log entry has an index, thus nil is disallowed.
  unless index.is_a?(Fixnum) && index >= 0
    raise ArgumentError, 'index must be a Fixnum and >= 0'
  end

  @waiters << Waiter.new(peer, index, condition)
end
signal(peer, index) click to toggle source
# File lib/floss/log_replicator.rb, line 36
def signal(peer, index)
  return unless index # There's nothing to do if no index is given, see #register.

  waiters = @waiters.delete_if do |waiter|
    next unless waiter.peer == peer
    waiter.index <= index
  end

  waiters.map(&:condition).each(&:signal)
end