module HTTPX::Plugins::Hedging::ConnectionMethods

  1. lib/httpx/plugins/hedging.rb

Public Class methods

new(*)
[show source]
    # File lib/httpx/plugins/hedging.rb
218 def initialize(*)
219   super
220   @is_hedge_connection = false
221 end

Public Instance methods

addresses=(addrs)
[show source]
    # File lib/httpx/plugins/hedging.rb
223 def addresses=(addrs)
224   try_yield_hedge_connection do |hedge_conn|
225     super.tap do
226       hedge_conn.addresses = addrs if hedge_conn
227     end
228   end
229 end
hedge_connection=(connection)
[show source]
    # File lib/httpx/plugins/hedging.rb
231 def hedge_connection=(connection)
232   @hedge_connection = connection
233 
234   return unless connection
235 
236   @is_hedge_connection = !connection.hedge_connection.nil?
237 
238   return if @is_hedge_connection
239 
240   connection.hedge_connection = self
241 end
mergeable?(connection)

connections should not merge with their hedge connections

[show source]
    # File lib/httpx/plugins/hedging.rb
258 def mergeable?(connection)
259   super && connection.hedge_connection != self
260 end
send(request)
[show source]
    # File lib/httpx/plugins/hedging.rb
262 def send(request)
263   super.tap do
264     if @hedge_connection && !request.hedge_request
265       request.hedge_request = hedge_request = request.dup
266       @hedge_connection.send(hedge_request)
267     end
268   end
269 end
try_yield_hedge_connection()
[show source]
    # File lib/httpx/plugins/hedging.rb
243 def try_yield_hedge_connection
244   return yield(nil) unless (hedge_conn = @hedge_connection)
245 
246   @hedge_connection = nil
247 
248   begin
249     hedge_conn.try_yield_hedge_connection do
250       yield(hedge_conn)
251     end
252   ensure
253     @hedge_connection = hedge_conn
254   end
255 end