Class: JS::PromiseScheduler
- Inherits:
-
Object
- Object
- JS::PromiseScheduler
- Defined in:
- lib/js.rb
Instance Method Summary collapse
- #await(promise) ⇒ Object
-
#initialize(loop) ⇒ PromiseScheduler
constructor
A new instance of PromiseScheduler.
Constructor Details
#initialize(loop) ⇒ PromiseScheduler
Returns a new instance of PromiseScheduler.
74 75 76 |
# File 'lib/js.rb', line 74 def initialize(loop) @loop = loop end |
Instance Method Details
#await(promise) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/js.rb', line 78 def await(promise) current = Fiber.current promise.call( :then, ->(value) { current.transfer(value, :success); nil }, ->(value) { current.transfer(value, :failure); nil } ) if @loop == current raise ( "JS::Object#await can be called only from RubyVM#evalAsync or RbValue#callAsync JS API\n" + "If you are using browser.script.iife.js, please ensure that you specify `data-eval=\"async\"` in your script tag\n" + "e.g. <script type=\"text/ruby\" data-eval=\"async\">puts :hello</script>\n" + "Or <script type=\"text/ruby\" data-eval=\"async\" src=\"path/to/script.rb\"></script>" ) end value, status = @loop.transfer raise JS::Error.new(value) if status == :failure value end |