Class: PredictionIO::AsyncResponse
- Inherits:
-
Object
- Object
- PredictionIO::AsyncResponse
- 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
-
#request ⇒ Object
readonly
The PredictionIO::AsyncRequest instance that created the current PredictionIO::AsyncResponse instance.
Instance Method Summary collapse
-
#get ⇒ Object
Get the Net::HTTPResponse instance.
-
#initialize(request, response = nil) ⇒ AsyncResponse
constructor
Create the response by saving the request, and optionally the Net::HTTPResponse object.
-
#set(response) ⇒ Object
Save a Net::HTTPResponse instance to the current instance.
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
#request ⇒ Object (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
#get ⇒ Object
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 |