Skip to content

Modernize dependency system with Promise-based run blockers#27028

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:runBlockers
Open

Modernize dependency system with Promise-based run blockers#27028
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:runBlockers

Conversation

@sbc100
Copy link
Copy Markdown
Collaborator

@sbc100 sbc100 commented May 29, 2026

Replace the callback-based dependenciesFulfilled/runDependencies system with a modern async/await approach using "run blockers" (Promises).

This modernizes the startup sequence, ensuring preRun and other startup hooks are executed exactly once by pausing and resuming execution flow instead of re-running the entry point.

To maintain backward compatibility, a bridge is implemented for the existing addRunDependency and removeRunDependency APIs, routing them through the new Promise-based blocking mechanism.

  • Make run() in postamble.js async to support await.
  • Implement $addRunBlocker and $resolveRunBlockers in libcore.js.
  • Bridge $addRunDependency and $removeRunDependency to use $addRunBlocker.
  • Wrap runDependencies == 0 check in ASSERTIONS guard to avoid empty block in optimized builds (fixes Closure Compiler warnings).

@sbc100 sbc100 requested review from brendandahl and kripken May 29, 2026 00:04
@sbc100 sbc100 requested a review from kleisauke May 29, 2026 00:28
@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented May 29, 2026

I'm petty happy about this change. Its something I've tried to do over the years several times and always given up in the end. This time with gemini's help I was able to get to the end of it.

The legacy versions of this API are also still supported which is nice.

The monitorRunDependencies system also still works, although its kind of pain. I wonder if folks actually depend on this counter-based callback.

@sbc100 sbc100 force-pushed the runBlockers branch 3 times, most recently from b0f8006 to b66f862 Compare May 29, 2026 05:55
Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

Comment thread site/source/docs/api_reference/preamble.js.rst Outdated
Comment thread site/source/docs/porting/emscripten-runtime-environment.rst Outdated
Comment thread site/source/docs/porting/emscripten-runtime-environment.rst Outdated
Comment thread test/codesize/test_small_js_flags.json Outdated
Comment thread test/codesize/test_codesize_file_preload.expected.js
Comment thread test/codesize/test_codesize_file_preload.json
Replace the callback-based dependenciesFulfilled/runDependencies system
with a modern async/await approach using "run blockers" (Promises).

This modernizes the startup sequence, ensuring preRun and other startup
hooks are executed exactly once by pausing and resuming execution flow
instead of re-running the entry point.

To maintain backward compatibility, a bridge is implemented for the
existing addRunDependency and removeRunDependency APIs, routing them
through the new Promise-based blocking mechanism.

- Make run() in postamble.js async to support await.
- Implement $addRunBlocker and $resolveRunBlockers in libcore.js.
- Bridge $addRunDependency and $removeRunDependency to use $addRunBlocker.
- Wrap runDependencies == 0 check in ASSERTIONS guard to avoid empty block in optimized builds (fixes Closure Compiler warnings).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants