Calling a func with an async operation fails
terrablue opened this issue · 1 comments
terrablue commented
The following code works:
await vm.evalAsync(`
puts "step 1"
JS.global.fetch("https://example.com").await
puts "step 3"
`);However, the following code fails with the error
RbError: /usr/local/lib/ruby/site_ruby/3.2.0/js.rb:86:in `await': JS::Object#await can be called only from RubyVM#evalAsync JS API`
const result = await vm.evalAsync(`
def foo()
puts "step 1"
JS.global.fetch("https://example.com").await
puts "step 3"
end
`)
await result.call("foo")Is there a way to define a function, call it later (from JS), and still use async operations?
In my use case, I'm precompiling framework routes, and executing them with (different) requests.
kateinoigakukun commented
It's a missing piece of the current @ruby/wasm-wasi JS API. We will support asyncCall or something like that. Until that, you need to use evalAsync to call the function. Of course, contribution is welcome :)