lib/freddy/sync_response_container.rb in freddy-0.5.3 vs lib/freddy/sync_response_container.rb in freddy-0.5.5

- old
+ new

@@ -3,26 +3,24 @@ class Freddy class SyncResponseContainer def initialize @mutex = Mutex.new + @resource = ConditionVariable.new end def call(response, delivery) @response = response @delivery = delivery - @mutex.synchronize { @waiting.wakeup } + @mutex.synchronize { @resource.signal } end def on_timeout(&block) @on_timeout = block end def wait_for_response(timeout) - @mutex.synchronize do - @waiting = Thread.current - @mutex.sleep(timeout) - end + @mutex.synchronize { @resource.wait(@mutex, timeout) } if !defined?(@response) @on_timeout.call raise TimeoutError.new( error: 'RequestTimeout',