Class: Px::Service::Client::Multiplexer
- Inherits:
-
Object
- Object
- Px::Service::Client::Multiplexer
- Defined in:
- lib/px/service/client/multiplexer.rb
Instance Attribute Summary collapse
-
#hydra ⇒ Object
Returns the value of attribute hydra.
-
#states ⇒ Object
Returns the value of attribute states.
Instance Method Summary collapse
- #context ⇒ Object
-
#do(request_or_future, retries: RetriableResponseFuture::DEFAULT_RETRIES) ⇒ Object
Queue a request on the multiplexer, with retry.
-
#initialize(params = {}) ⇒ Multiplexer
constructor
A new instance of Multiplexer.
-
#run ⇒ Object
Start the multiplexer.
Constructor Details
#initialize(params = {}) ⇒ Multiplexer
Returns a new instance of Multiplexer.
6 7 8 |
# File 'lib/px/service/client/multiplexer.rb', line 6 def initialize(params = {}) self.hydra = Typhoeus::Hydra.new(params) end |
Instance Attribute Details
#hydra ⇒ Object
Returns the value of attribute hydra.
3 4 5 |
# File 'lib/px/service/client/multiplexer.rb', line 3 def hydra @hydra end |
#states ⇒ Object
Returns the value of attribute states.
4 5 6 |
# File 'lib/px/service/client/multiplexer.rb', line 4 def states @states end |
Instance Method Details
#context ⇒ Object
10 11 12 13 |
# File 'lib/px/service/client/multiplexer.rb', line 10 def context Fiber.new{ yield }.resume self end |
#do(request_or_future, retries: RetriableResponseFuture::DEFAULT_RETRIES) ⇒ Object
Queue a request on the multiplexer, with retry
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/px/service/client/multiplexer.rb', line 17 def do(request_or_future, retries: RetriableResponseFuture::DEFAULT_RETRIES) response = request_or_future if request_or_future.is_a?(Typhoeus::Request) response = RetriableResponseFuture.new(request_or_future, retries: retries) elsif !request_or_future.is_a?(RetriableResponseFuture) || request_or_future.completed? return request_or_future end # Will automatically queue the request on the hydra response.hydra = hydra response end |
#run ⇒ Object
Start the multiplexer.
32 33 34 |
# File 'lib/px/service/client/multiplexer.rb', line 32 def run hydra.run end |