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)
84
84
self [ sym ] . typeof == "function"
85
85
end
86
86
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
87
94
def await
88
95
# Promise.resolve wrap a value or flattens promise-like object and its thenable chain
89
96
promise = JS . global [ :Promise ] . resolve ( self )
You can’t perform that action at this time.
0 commit comments