Skip to content

Calling a func with an async operation fails #339

@terrablue

Description

@terrablue

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions