Class: PubControlClientCallbackHandler
- Inherits:
-
Object
- Object
- PubControlClientCallbackHandler
- Defined in:
- lib/pcccbhandler.rb
Overview
The PubControlClientCallbackHandler class is used internally for allowing an async publish call made from the PubControl class to execute a callback method only a single time. A PubControl instance can potentially contain many PubControlClient instances in which case this class tracks the number of successful publishes relative to the total number of PubControlClient instances. A failure to publish in any of the PubControlClient instances will result in a failed result passed to the callback method and the error from the first encountered failure.
Instance Method Summary collapse
-
#handler(success, message) ⇒ Object
The handler method which is executed by PubControlClient when publishing is complete.
-
#handler_method_symbol ⇒ Object
This method is used as a workaround to retrieve the handler method symbol.
-
#initialize(num_calls, callback) ⇒ PubControlClientCallbackHandler
constructor
The initialize method accepts: a num_calls parameter which is an integer representing the number of PubControlClient instances, and a callback method to be executed after all publishing is complete.
Constructor Details
#initialize(num_calls, callback) ⇒ PubControlClientCallbackHandler
The initialize method accepts: a num_calls parameter which is an integer representing the number of PubControlClient instances, and a callback method to be executed after all publishing is complete.
21 22 23 24 25 26 |
# File 'lib/pcccbhandler.rb', line 21 def initialize(num_calls, callback) @num_calls = num_calls @callback = callback @success = true = nil end |
Instance Method Details
#handler(success, message) ⇒ Object
The handler method which is executed by PubControlClient when publishing is complete. This method tracks the number of publishes performed and when all publishes are complete it will call the callback method originally specified by the consumer. If publishing failures are encountered only the first error is saved and reported to the callback method.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pcccbhandler.rb', line 34 def handler(success, ) if !success and @success @success = false = end @num_calls -= 1 if @num_calls <= 0 @callback.call(@success, ) end end |
#handler_method_symbol ⇒ Object
This method is used as a workaround to retrieve the handler method symbol. TODO: how to get handler symbol without this method?
47 48 49 |
# File 'lib/pcccbhandler.rb', line 47 def handler_method_symbol return method(:handler) end |