Module: Paleth::Liar

Included in:
Db, Eth, Net, Personal, Web3
Defined in:
lib/paleth/liar.rb

Instance Method Summary collapse

Instance Method Details

#make_promise(object, method_name, *args) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/paleth/liar.rb', line 5

def make_promise(object, method_name, *args)
  promise = Promise.new

  callback = proc do |err, result|
    if err
      promise.reject err
    else
      result = yield result if block_given?
      promise.resolve result
    end
  end

  params = [args, callback].flatten
  object.JS[method_name].call(*params)

  promise
end