-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use Javy with asynchronous JavaScript code? (experimental_event_loop) #626
Comments
I'm not able to reproduce the issue you ran into. I created a module with this code: (async () => {
const result = await foo();
console.log(result);
})();
async function foo(params) {
return 'blah';
} Then tested that compiling this with the default configuration outputs Error while running JS: Adding tasks to the event queue is not supported:
Then I tested building with event loop support enabled:
Note that the Can you double-check you're still seeing the issue if you run the steps I've outlined above in the same order? If you are seeing the same issue, can you please include all commands you ran in the exact order you ran them including any outputs from those commands? |
I tried your snippet and you are right. With this snippet, everything works as it should. However, I digged deeper to figure out why it doesn't work for my setup whereas it does for yours: In the example that you provided, no actual async logic (such as IO or event loop activities) is performed. Most likely, your code is desugared under the hood to a (async () => {
const result = await foo();
console.log(result);
})();
async function foo(params) {
await Promise.resolve("dummy");
return 'blah';
} This snippet worked and as expected, If actual async logic is involved, the issues come up. See this minimal example using (async () => {
console.log("start");
const result = await foo();
console.log(result);
})();
async function foo(params) {
await (
new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 1000);
})
);
return 'blah';
} Notice, I also added a log for "start" at the beginning of the async IIFE. When running this example, "start" is printed out, while "blah" is not. For the execution, this time I used the wasmtime cli in the exact same way as you specified in your response. |
Ah! So you're not seeing the error message about adding tasks to the event queue not being supported. But rather you're expecting to see output but not seeing the output. The script you provided won't execute successfully since Javy does not provide an implementation for That said, there is a bug in that Javy should throw an error that an undefined function has been invoked. Running setTimeout(() => { console.log("hello") }, 1000); for example results in
|
Filed #627 to track the lack of error messages and traps when there's an error in |
Yes, that the Also, I wasn't aware that That no error is thrown at all is therefore a bug as you said. Since this is captured in #627, I think my question is answered, so feel free to close the issue. |
What is your question?
Hi, I try to execute asynchronous JavaScript code using Javy. the simplified JavaScript code looks like this:
I am using a setup where I use the Javy Provider Module created via
javy emit-provider -o javy-provider.wasm
.The JavaScript code itself is compiled via
javy compile my.js -o out.wasm -d
.I execute everything in Wasmtime, and for sync code this works as expected. When using async code in the JavaScript code, I get the error
Error while running JS: Adding tasks to the event queue is not supported
.I researched the origin of the issue and found out that in the file
crates/core/src/execution.rs
pending code (i.e. Promises) is only executed if the featureexperimental_event_loop
is set.Therefore, I tried the following steps to fix my issue:
cargo build -p javy-core --target wasm32-wasi -r --features experimental_event_loop
cargo build -p javy-cli -r --features experimental_event_loop
Unfortunately, I ended up with the very same issue. Have I missed something?
Thanks for your help and clarification
P.S.: I am running on ARM-based MacOS, Rust 1.76.0, and built Javy on commit 8f4468c. The wasmtime(-wasi)/wasi-common version for the execution of the WASM is 15.0.0
The text was updated successfully, but these errors were encountered: