Class: Ccrpc::RpcConnection::Call
- Inherits:
-
Object
- Object
- Ccrpc::RpcConnection::Call
- Defined in:
- lib/ccrpc/rpc_connection.rb
Overview
The context of a received call.
Instance Attribute Summary collapse
-
#answer ⇒ Hash{String => String}
List of parameters send back to the called.
-
#conn ⇒ RpcConnection
readonly
The used connection.
-
#func ⇒ String
readonly
Called function.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#params ⇒ Hash{String => String}
readonly
List of parameters passed with the call.
Instance Method Summary collapse
-
#call_back(func, params = {}, &block) ⇒ Object
Send a dedicated callback to the caller’s block.
-
#initialize(conn, func, params = {}, id) ⇒ Call
constructor
A new instance of Call.
Constructor Details
#initialize(conn, func, params = {}, id) ⇒ Call
Returns a new instance of Call.
44 45 46 47 48 49 50 |
# File 'lib/ccrpc/rpc_connection.rb', line 44 def initialize(conn, func, params={}, id) @conn = conn @func = func @params = params @id = id @answer = nil end |
Instance Attribute Details
#answer ⇒ Hash{String => String}
Returns List of parameters send back to the called.
41 42 43 |
# File 'lib/ccrpc/rpc_connection.rb', line 41 def answer @answer end |
#conn ⇒ RpcConnection (readonly)
Returns The used connection.
34 35 36 |
# File 'lib/ccrpc/rpc_connection.rb', line 34 def conn @conn end |
#func ⇒ String (readonly)
Returns Called function.
36 37 38 |
# File 'lib/ccrpc/rpc_connection.rb', line 36 def func @func end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
39 40 41 |
# File 'lib/ccrpc/rpc_connection.rb', line 39 def id @id end |
#params ⇒ Hash{String => String} (readonly)
Returns List of parameters passed with the call.
38 39 40 |
# File 'lib/ccrpc/rpc_connection.rb', line 38 def params @params end |
Instance Method Details
#call_back(func, params = {}, &block) ⇒ Object
Send a dedicated callback to the caller’s block.
If Ccrpc::RpcConnection#call is called with both function name and block, then it’s possible to call back to this dedicated block through #call_back . The library ensures, that the callback ends up in the corresponding call block and in the same thread as the caller, even if there are multiple simultaneous calls are running at the same time in different threads or by using lazy_answers
.
Yielded parameters and returned objects are described in Ccrpc::RpcConnection#call.
72 73 74 75 |
# File 'lib/ccrpc/rpc_connection.rb', line 72 def call_back(func, params={}, &block) raise CallAlreadyReturned, "Callback is no longer possible since the call already returned #{self.inspect}" if @answer conn.send(:call_intern, func, params, @id, &block) end |