Class: Lowdown::Client::RequestGroup
- Inherits:
-
Object
- Object
- Lowdown::Client::RequestGroup
- Defined in:
- lib/lowdown/client/request_group.rb
Overview
Note:
These callbacks are executed on a separate thread, so be aware about this when accessing shared resources from a block callback.
Implements the Lowdown::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.
Defined Under Namespace
Classes: Callbacks
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(client, condition) ⇒ RequestGroup
constructor
A new instance of RequestGroup.
- #send_notification(notification, delegate: nil, context: nil, &block) ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(client, condition) ⇒ RequestGroup
Returns a new instance of RequestGroup.
17 18 19 20 |
# File 'lib/lowdown/client/request_group.rb', line 17 def initialize(client, condition) @client = client @callbacks = Callbacks.new(condition) end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
15 16 17 |
# File 'lib/lowdown/client/request_group.rb', line 15 def callbacks @callbacks end |
Instance Method Details
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/lowdown/client/request_group.rb', line 31 def empty? @callbacks.empty? end |
#send_notification(notification, delegate: nil, context: nil, &block) ⇒ Object
22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
35 36 37 |
# File 'lib/lowdown/client/request_group.rb', line 35 def terminate @callbacks.terminate if @callbacks.alive? end |