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
Using await before go.run(inst) of wasm_exec await indefinitely #49710
Comments
can you provide a self contained reproducer? |
please find a repo where the case is reproductible It is a monorepo with a wasm lib and a frontend in Ember which use the wasm lib |
Here is a much more simple example : https://github.com/fiscafacile/exampleGoWasmIssue49710 The Run button never get enabled, event after fetch(main.wasm) and Wasm Init is done ("Go WebAssembly Initialized" in Console) |
I think this feature is working as intended. The promise returned by If you want the host application to wait for the Wasm program to finish initializing, you can create a promise in the host application and resolve it from the Wasm program. For example, you might modify the code in the original post like this: let isReady = new Promise((resolve) => {
// @ts-ignore
window.onWasmInitialized = resolve;
});
export async function loadCff2Wasm() {
const go = new Go();
const result = await WebAssembly.instantiateStreaming(fetch('cff2.wasm'), go.importObject);
go.run(result.instance);
await isReady;
} You can then add the following call in the Go Wasm program after it is initialized: js.Global().Get("onWasmInitialized").Invoke() This call will resolve the You might also consider calling and awaiting setTimeout(async () => {
await go.run(result.instance);
console.log('Wasm program exited! ...Restart it?');
}); |
Closing based on the last comment. Please comment if you disagree. |
The Go runtime needs a small amount of time to initialize. However the promise returned by `Go().run()` only resolves once the wasm process exits. Wheich means we need another way to wait for the initialization to be completed. Solution taken from: golang/go#49710 (comment)
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Trying to run wasm module with await, then wait is lock
I'm using it with an ember service. calling fetchTransactions will run indefinitely.
The text was updated successfully, but these errors were encountered: