File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,13 @@ def respond_to_missing?(sym, include_private)
8484 self [ sym ] . typeof == "function"
8585 end
8686
87+ # Await a JavaScript Promise like `await` in JavaScript.
88+ # This method looks like a synchronous method, but it actually runs asynchronously using fibers.
89+ #
90+ # JS.eval("return new Promise((ok) => setTimeout(ok(42), 1000))").await # => 42 (after 1 second)
91+ # JS.global.fetch("https://example.com").await # => [object Response]
92+ # JS.eval("return 42").await # => 42
93+ # JS.eval("return new Promise((ok, err) => err(new Error())").await # => raises JS::Error
8794 def await
8895 # Promise.resolve wrap a value or flattens promise-like object and its thenable chain
8996 promise = JS . global [ :Promise ] . resolve ( self )
You can’t perform that action at this time.
0 commit comments