Class: PredictionIO::AsyncResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/predictionio/async_response.rb

Overview

This class encapsulates an asynchronous response that will block the caller until the response is available.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response = nil) ⇒ AsyncResponse

Create the response by saving the request, and optionally the Net::HTTPResponse object.



11
12
13
14
15
# File 'lib/predictionio/async_response.rb', line 11

def initialize(request, response = nil)
  @request = request
  @response = Queue.new
  set(response) if response
end

Instance Attribute Details

#requestObject (readonly)

The PredictionIO::AsyncRequest instance that created the current PredictionIO::AsyncResponse instance.



8
9
10
# File 'lib/predictionio/async_response.rb', line 8

def request
  @request
end

Instance Method Details

#getObject

Get the Net::HTTPResponse instance. This will block if the response is not yet available.



24
25
26
# File 'lib/predictionio/async_response.rb', line 24

def get
  @response.pop
end

#set(response) ⇒ Object

Save a Net::HTTPResponse instance to the current instance. This will unblock any caller that called #get.



19
20
21
# File 'lib/predictionio/async_response.rb', line 19

def set(response)
  @response.push(response)
end