Method: Farcall::Endpoint#call

Defined in:
lib/farcall/endpoint.rb

#call(name, *args, **kwargs, &block) ⇒ Farcall::Promise

Call the remote party, non blocking, returns Promise instance to handle the remote return valy asynchronously (recommended way).

Optionally the block could be provided that takes |error, result| parameters. Error must be nil or

Hashie::Mash.new({'class' =>, 'text' => text [, data: {some_data}] })

if error is presented, the result is always the nil.

Usually, using #remote which returns Interface is more effective rather than this low-level method.

The returned Promise instance let add any number of callbacks on commend execution, success or failure.

Parameters:

  • name (String)

    of the remote command

Returns:


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/farcall/endpoint.rb', line 99

def call(name, *args, **kwargs, &block)
  promise = Farcall::Promise.new
  @send_lock.synchronize {
      @waiting[@out_serial] = -> (error, result) {
        block.call(error, result) if block
        if error
          promise.set_fail error
        else
          promise.set_success result
        end
      }
      _send(cmd: name.to_s, args: args, kwargs: kwargs)
  }
  promise
end