class Lowdown::Client::RequestGroup

Implements the {Connection::DelegateProtocol} to provide a way to group requests and hal the caller thread while waiting for the responses to come in. In addition to the regular delegate message based callbacks, it also allows for a more traditional blocks-based callback mechanism.

@note These callbacks are executed on a separate thread, so be aware about this when accessing shared resources

from a block callback.

Attributes

callbacks[R]

Public Class Methods

new(client, condition) click to toggle source
# File lib/lowdown/client/request_group.rb, line 17
def initialize(client, condition)
  @client = client
  @callbacks = Callbacks.new(condition)
end

Public Instance Methods

empty?() click to toggle source
# File lib/lowdown/client/request_group.rb, line 31
def empty?
  @callbacks.empty?
end
send_notification(notification, delegate: nil, context: nil, &block) click to toggle source
# File lib/lowdown/client/request_group.rb, line 22
def send_notification(notification, delegate: nil, context: nil, &block)
  return unless @callbacks.alive?
  if (block.nil? && delegate.nil?) || (block && delegate)
    raise ArgumentError, "Either a delegate object or a block should be provided."
  end
  @callbacks.add(notification.formatted_id, block || delegate)
  @client.send_notification(notification, delegate: @callbacks.async, context: context)
end
terminate() click to toggle source
# File lib/lowdown/client/request_group.rb, line 35
def terminate
  @callbacks.terminate if @callbacks.alive?
end