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.


26
27
28
29
30
# File 'lib/predictionio/async_response.rb', line 26

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.


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

def request
  @request
end

Instance Method Details

#getObject

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


39
40
41
# File 'lib/predictionio/async_response.rb', line 39

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.


34
35
36
# File 'lib/predictionio/async_response.rb', line 34

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