Skip to content

Add emscripten_queue_microtask #24483

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
wants to merge 1 commit into from

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 3, 2025

This change adds a new emscripten_queue_microtask API to match the long standing web API (also available in node).

See https://developer.mozilla.org/en-US/docs/Web/API/Window/queueMicrotask

For now, I'm adding this without a polyfill so usage of the API will crash on very old targets. We could potentially polyfill using something like setTimeout, but the semantics are a little different so I'm not sure it worth doing.

Split out from #24481

@sbc100 sbc100 requested a review from kripken June 3, 2025 23:04
This change adds a new `emscripten_queue_microtask` API to match the
long standing web API (also available in node).

See https://developer.mozilla.org/en-US/docs/Web/API/Window/queueMicrotask

For now, I'm adding this without a polyfill so usage of the API will
crash on very old targets.  We could potentially polyfill using
something like setTimeout, but the semantics are a little different so
I'm not sure it worth doing.

Split out from emscripten-core#24481
@sbc100 sbc100 force-pushed the queue_microtask branch from 8d9ef56 to 86c66e9 Compare June 3, 2025 23:05
@sbc100 sbc100 requested review from tlively and dschuff June 3, 2025 23:07
@sbc100
Copy link
Collaborator Author

sbc100 commented Jun 3, 2025

It turns out that this probably is not needed for #24481, but perhaps its worth adding anyway? I'm not sure.

Also, apparently this is polyfillable using Promise.resolve().then(...)

@dschuff
Copy link
Member

dschuff commented Jun 3, 2025

I think that this makes sense given the other stuff that we have in eventloop.h
Should this also go in html5.h and its documentation?

Copy link
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.

lgtm with docs

@sbc100
Copy link
Collaborator Author

sbc100 commented Jun 4, 2025

Abandoning for now. Hopefully not needed since Prosmise.resolve().then( is at least as good and more portable.

@sbc100 sbc100 closed this Jun 4, 2025
@sbc100 sbc100 deleted the queue_microtask branch June 4, 2025 20:57
@dschuff
Copy link
Member

dschuff commented Jun 4, 2025

Does it make sense to have a C API to do this? (even if it's just backed by Promise.resolve().then )?

@sbc100
Copy link
Collaborator Author

sbc100 commented Jun 4, 2025

Does it make sense to have a C API to do this? (even if it's just backed by Promise.resolve().then )?

I'm not sure .. it depends how hard it is to write Promise.resolve().then using the current promise C API.. I'll look into that.

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.

3 participants