Skip to content

Asyncify and postRun() #12402

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

Closed
danchitnis opened this issue Oct 1, 2020 · 4 comments · Fixed by #24089
Closed

Asyncify and postRun() #12402

danchitnis opened this issue Oct 1, 2020 · 4 comments · Fixed by #24089
Labels

Comments

@danchitnis
Copy link

I noticed that when using Asyncify, the Module.postRun() only runs once after the first call of emscripten_sleep(). Is this behaviour expected? Ideally we want the postRun() to run after then main() function returns and the programme exits, not when an async function called. Otherwise I don't know when my programme has exited to do my clean-up routines. Thanks.
Amazing work with Emscripten + Asyncify 👍

@curiousdannii
Copy link
Contributor

You might be able to use addOnExit() instead, if you compile with EXIT_RUNTIME.

@SomeDevHere
Copy link

Asyncify ends up calling postRun() as wasm exits when emscripten_sleep is called to allow the js stack to unwind to allow asynchronous activity to occur and the wasm binary is called again to resume execution.

To prevent program from exiting, Asyncify sets noExitRuntime=true to prevent any function added using addOnExit() from running, but it does not set noExitRuntime back. Even if noExitRuntime is changed back after emscripten_sleep is called, the exit functions are no longer going to be called as the wasm binary is resumed in a completely different function than callMain which calls those functions.

Appending a function into Asyncify.asyncFinalizers might work as it is called after all asynchronous activity is done and the program exits, but I have not tested it.

@stale
Copy link

stale bot commented Jul 31, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@sbc100
Copy link
Collaborator

sbc100 commented Aug 7, 2022

bump

msorvig pushed a commit to msorvig/emscripten that referenced this issue Apr 10, 2025
await callMain(), which is an async function if JSPI
is enabled.

Fixes emscripten-core#12402.
msorvig pushed a commit to msorvig/emscripten that referenced this issue Apr 11, 2025
Make doRun() be async when JSPI is enabled. await callMain(),
which is similarly an async function when JSPI is enabled.

Fixes emscripten-core#12402.
msorvig pushed a commit to msorvig/emscripten that referenced this issue Apr 14, 2025
Make doRun() be async when JSPI is enabled. await callMain(),
which is similarly an async function when JSPI is enabled.

Fixes emscripten-core#12402.
msorvig pushed a commit to msorvig/emscripten that referenced this issue Apr 15, 2025
Make doRun() be async when JSPI is enabled. await callMain(),
which is similarly an async function when JSPI is enabled.

Fixes emscripten-core#12402.
msorvig pushed a commit to msorvig/emscripten that referenced this issue Apr 15, 2025
Make doRun() be async when JSPI is enabled. await callMain(),
which is similarly an async function when JSPI is enabled.

Fixes emscripten-core#12402.
@sbc100 sbc100 closed this as completed in 858d13b Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants