Sha256: 3ea21fdf8b4cc7eb9339b7d30450049bdd2edbe30b069537b12c895001eeaa65

Contents?: true

Size: 660 Bytes

Versions: 7

Compression:

Stored size: 660 Bytes

Contents

require 'timeout'

class Freddy
  class SyncResponseContainer
    def call(response, delivery)
      @response = response
      @delivery = delivery
    end

    def wait_for_response(timeout)
      Timeout::timeout(timeout) do
        sleep 0.001 until filled?
      end

      if @response[:error] == 'RequestTimeout'
        raise TimeoutError.new(@response)
      elsif !@delivery || @delivery.properties[:type] == 'error'
        raise InvalidRequestError.new(@response)
      else
        @response
      end
    end

    private

    def to_proc
      Proc.new {|*args| self.call(*args)}
    end

    def filled?
      !@response.nil?
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
freddy-0.4.2 lib/freddy/sync_response_container.rb
freddy-0.4.1 lib/freddy/sync_response_container.rb
freddy-0.4.0 lib/freddy/sync_response_container.rb
freddy-0.3.7 lib/freddy/sync_response_container.rb
freddy-0.3.6 lib/freddy/sync_response_container.rb
freddy-0.3.5 lib/freddy/sync_response_container.rb
freddy-0.3.4 lib/freddy/sync_response_container.rb