Sha256: a6cce556163054ca928c86e5fd6ae97363b77e2eac08ece95aa30a74839597ba

Contents?: true

Size: 562 Bytes

Versions: 4

Compression:

Stored size: 562 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 !@delivery || @delivery.properties[:type] == 'error'
        raise ErrorResponse.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

4 entries across 4 versions & 1 rubygems

Version Path
freddy-0.3.3 lib/freddy/sync_response_container.rb
freddy-0.3.2 lib/freddy/sync_response_container.rb
freddy-0.3.1 lib/freddy/sync_response_container.rb
freddy-0.3.0 lib/freddy/sync_response_container.rb