Fix wasm worker: poll for synthesize and handle wasmoocaml events#2322
Merged
Conversation
The wasm_of_ocaml launcher loads and instantiates the wasm module asynchronously, then runs the OCaml entry point that calls `Js.export "synthesize" ...`. The previous fixed 1s setTimeout in the worker raced against this and produced `ReferenceError: synthesize is not defined` on the deployed site (the wasm blob is now ~13.8 MB and routinely takes longer to load than 1s). Replace the timeout with a 50ms poll for `self.synthesize`, and also subscribe to the `wasmoocaml:loaded` / `wasmoocaml:error` events introduced in ocaml-wasm/wasm_of_ocaml#143 so we install the handler immediately on success and surface load failures back to the page instead of looping forever. The loaded handler logs a note that the polling fallback can be removed once the deployed wasm_of_ocaml ships these events.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setTimeoutinfiat-html/wasm_fiat_crypto_worker.jswith a 50ms poll forself.synthesize. The currentwasm_of_ocamllauncher loads/instantiates the (~13.8 MB) wasm asynchronously and only then runs the OCaml entry that doesJs.export "synthesize" ..., so on the deployed site the timeout regularly elapsed before initialization finished, producingReferenceError: synthesize is not defined.wasmoocaml:loaded/wasmoocaml:errorevents introduced in Wasm: dispatch lifecycle events when async instantiation completes ocaml-wasm/wasm_of_ocaml#143: install the handler immediately on success, surface load failures back to the page (instead of polling forever), and log a note on the loaded path that the polling fallback can be removed once the deployedwasm_of_ocamlships these events.Test plan
ReferenceError.wasm_of_ocamlincludes Wasm: dispatch lifecycle events when async instantiation completes ocaml-wasm/wasm_of_ocaml#143, verify thewasmoocaml:loadedconsole message appears and remove the polling fallback.