-
Notifications
You must be signed in to change notification settings - Fork 9
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
[BUG] wasm is not ready when DOMContentLoaded fires and does not trigger an event when it is loaded #11
Comments
I don't think there is any way to fix that since compiling and instantiating WebAssembly code is asynchronous. Your Wasm code should somehow signal when it is ready. |
Could the generated .js file be made to trigger some event when the wasm code is ready? It seems like the cleanest place to do this is using the Promise of the async function in the generated .js wrapper, you could insert something like .then((value) => {
dispatchEvent(new CustomEvent('wasmCodeLoaded', {detail: {src}} ));
}).catch((error) => {
dispatchEvent(new CustomEvent('wasmCodeLoadingError', {detail: {src, error}}));
}) And perhaps It seems cleaner to me to do it in the autogenerated javascript code wrapper, and matches more closely with |
Work around asnyc wasm code cf ocaml-wasm/wasm_of_ocaml#11
Describe the bug
In
fiat-html.tar.gz (unpack the tar.gz, run
python -m http.server 8000
in thefiat-html
directory, and then navigate to http://localhost:8000/?argv=%5B%22-h%22%5D&interactive&wasm in Chrome), the code fails with "ReferenceError: synthesize is not defined". But if you change thesetTimeout
inmain.js
to be 1000 instead of 1, so that it waits a full second, then the code works fine.The .tar.gz contains the standalone wasm_fiat_crypto.ml used to generate the wasm with
-package unix -w -20 -g -package js_of_ocaml -linkpkg
and thenwasm_of_ocaml --source-map --no-inline
.Expected behavior
All exported functions should be available by the time DOMContentLoaded fires
Versions
Chrome Version 119.0.6045.160 (Official Build) (64-bit)
ocaml-option-fp.1,ocaml-variants.4.14.1+options
The text was updated successfully, but these errors were encountered: