Class: JS::Promise

Inherits:
Proxy
  • Object
show all
Defined in:
lib/js/proxy.rb

Overview

Ruby wrapper for JavaScript promises with chain-preserving return values.

Constant Summary

Constants inherited from Proxy

JS::Proxy::IRREGULARS

Instance Method Summary collapse

Methods inherited from Proxy

#[], #[]=, #each, #initialize, #length, #method_missing, #native, #native=, #respond_to_missing?, #to_n, #to_str

Methods included from Helpers

#native_methods, #wrap_result

Constructor Details

This class inherits a constructor from JS::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JS::Proxy

Instance Method Details

#catch(&block) ⇒ Object



227
228
229
230
# File 'lib/js/proxy.rb', line 227

def catch(&block)
  result = block ? `#{to_n}.catch(#{promise_callback(block)})` : `#{to_n}.catch()`
  Promise.new(result)
end

#then(&block) ⇒ Object



222
223
224
225
# File 'lib/js/proxy.rb', line 222

def then(&block)
  result = block ? `#{to_n}.then(#{promise_callback(block)})` : `#{to_n}.then()`
  Promise.new(result)
end