Add emscripten_promising_count() for querying in-flight async invocations#27377
Open
guybedford wants to merge 1 commit into
Open
Add emscripten_promising_count() for querying in-flight async invocations#27377guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
…ions Returns the number of async (promising) wasm invocations currently in flight, under both ASYNCIFY and JSPI. For JSPI the counter is bumped in Asyncify.makeAsyncFunction around each promising call, with all WebAssembly.promising usage now routed through it; for ASYNCIFY it tracks the single suspendable invocation from its first unwind until its final rewind completes.
sbc100
reviewed
Jul 18, 2026
sbc100
left a comment
Collaborator
There was a problem hiding this comment.
I think the current state is the we only support a single suspended stack at once, either with ASYNCIFY or JSPI? At least I think it should be.
If I'm wrong and we don't currently enforce this for JSPI, then perhaps we should land the internals of this counter, along with an assertion if its ever exceeds 1?
We can then add a the public function, once we add the ASYNCIFY_RENTRANT option (until we add that we should not allow more than one suspended stack I think).
If/when we do add a public function here, perhaps it should be called something like emscripten_suspended_stack_count? Or emscripten_asyncify_active_stacks? Just shedding here.
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.
This adds a new
emscripten_promising_count()function returning the number of async (promising) wasm invocations currently in flight, entered but with their returned promise not yet settled, under both ASYNCIFY and JSPI.This allows runtime code to detect whether any async wasm invocations are pending, for example to verify or assert reentrancy invariants.
ASYNCIFY==2), the counter is bumped inAsyncify.makeAsyncFunctionaround each promising invocation, decrementing when the returned promise settles. AllWebAssembly.promisingusage (exports,dynCall, embind,makeDynCallcodegen) is now routed throughmakeAsyncFunctionas a single chokepoint, so this is a single bump per invocation rather than per import call.One documented asymmetry: under JSPI a promising export counts for its entire invocation, while under ASYNCIFY an invocation is only counted once it first suspends.
Includes a new
test_promising_countcore test run under both ASYNCIFY and JSPI, observing the count from JS during anemscripten_sleepsuspension, from C after resume, and confirming it returns to 0 after the invocation settles. Docs and ChangeLog updated.Made with AI assistance under my review