Class: Ccrpc::RpcConnection::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/ccrpc/rpc_connection.rb

Overview

The context of a received call.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, func, params = {}, id) ⇒ 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

#answerHash{String => String}



41
42
43
# File 'lib/ccrpc/rpc_connection.rb', line 41

def answer
  @answer
end

#connRpcConnection (readonly)



34
35
36
# File 'lib/ccrpc/rpc_connection.rb', line 34

def conn
  @conn
end

#funcString (readonly)



36
37
38
# File 'lib/ccrpc/rpc_connection.rb', line 36

def func
  @func
end

#idObject (readonly)

Returns the value of attribute id.



39
40
41
# File 'lib/ccrpc/rpc_connection.rb', line 39

def id
  @id
end

#paramsHash{String => String} (readonly)



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