You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#1905 added syntactic support for async + #[wasm_bindgen(start)], which means it's accepted by the macro, but it's not changing anything on the JS side.
It's leading to confusing race conditions where an async function marked with #[wasm_bindgen(start)] is doing some preparatory async work, and user expects it to be finished by the time await init(); is finished on --target web (or an equivalent or other targets).
On practice, however, wasm-bindgen generated init will only kickstart the async process, but not wait for its completion, so code like this fails in unexpected ways:
#[wasm_bindgen(start)]pubasyncfnstart(){// ...init some global state}#[wasm_bindgen]pubfnfoo(){// ...access the global state assuming it's ready}
importinit,{foo}from'./pkg';awaitinit();foo();
Proposed Solution
async functions marked with #[wasm_bindgen(start)] should create a promise that is awaited or returned from the wasm-bindgen-generated init function (or its equivalent on other targets).
Alternatives
As an alternative, async + #[wasm_bindgen(start)] could be disallowed to make it more clear that the function itself won't be awaited.
Additional Context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered:
Motivation
#1905 added syntactic support for
async
+#[wasm_bindgen(start)]
, which means it's accepted by the macro, but it's not changing anything on the JS side.It's leading to confusing race conditions where an
async
function marked with#[wasm_bindgen(start)]
is doing some preparatory async work, and user expects it to be finished by the timeawait init();
is finished on--target web
(or an equivalent or other targets).On practice, however, wasm-bindgen generated
init
will only kickstart the async process, but not wait for its completion, so code like this fails in unexpected ways:Proposed Solution
async
functions marked with#[wasm_bindgen(start)]
should create a promise that is awaited or returned from the wasm-bindgen-generatedinit
function (or its equivalent on other targets).Alternatives
As an alternative,
async
+#[wasm_bindgen(start)]
could be disallowed to make it more clear that the function itself won't be awaited.Additional Context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: