lib/httpx/plugins/circuit_breaker/circuit_store.rb in httpx-1.1.2 vs lib/httpx/plugins/circuit_breaker/circuit_store.rb in httpx-1.1.3

- old
+ new

@@ -1,9 +1,7 @@ # frozen_string_literal: true -require "mutex_m" - module HTTPX::Plugins::CircuitBreaker using HTTPX::URIExtensions class CircuitStore def initialize(options) @@ -13,21 +11,21 @@ options.circuit_breaker_reset_attempts_in, options.circuit_breaker_break_in, options.circuit_breaker_half_open_drip_rate ) end - @circuits.extend(Mutex_m) + @circuits_mutex = Thread::Mutex.new end def try_open(uri, response) - circuit = @circuits.synchronize { get_circuit_for_uri(uri) } + circuit = @circuits_mutex.synchronize { get_circuit_for_uri(uri) } circuit.try_open(response) end def try_close(uri) - circuit = @circuits.synchronize do + circuit = @circuits_mutex.synchronize do return unless @circuits.key?(uri.origin) || @circuits.key?(uri.to_s) get_circuit_for_uri(uri) end @@ -35,10 +33,10 @@ end # if circuit is open, it'll respond with the stored response. # if not, nil. def try_respond(request) - circuit = @circuits.synchronize { get_circuit_for_uri(request.uri) } + circuit = @circuits_mutex.synchronize { get_circuit_for_uri(request.uri) } circuit.respond end private