Repository navigation
Add 'callback' async variants for JS library functions - #27954
Open
guybedford wants to merge 1 commit into
Open
guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
guybedford
added this pull request to stack #27955
October 12, 2026 23:15
guybedford
force-pushed
the
gbedford/callback-form
branch
2 times, most recently
from
October 12, 2026 23:39
8c29335 to
76ff676
Compare
guybedford
removed this pull request from stack #27955
October 12, 2026 23:39
guybedford
added this pull request to stack #27957
October 12, 2026 23:40
guybedford
removed this pull request from stack #27957
October 12, 2026 23:40
guybedford
added this pull request to stack #27958
October 12, 2026 23:41
guybedford
force-pushed
the
gbedford/callback-form
branch
3 times, most recently
from
October 13, 2026 00:35
96c852c to
7330e65
Compare
guybedford
force-pushed
the
gbedford/callback-form
branch
from
October 14, 2026 23:16
7330e65 to
05d7c96
Compare
guybedford
force-pushed
the
gbedford/callback-form
branch
from
October 14, 2026 23:49
05d7c96 to
1ca7889
Compare
foo_callback(args..., callback, arg) runs the same body and calls callback(err, result, arg) on the calling thread once the result is available, err set if its Promise rejects, always after the call has returned. A pending callback holds the runtime alive like a timer. From a pthread it is emscripten_proxy_callback_with_ctx of the main-thread body, with the result riding in the proxied call's arg as for _promise.
guybedford
removed this pull request from stack #27958
October 20, 2026 04:34
guybedford
added this pull request to stack #28023
October 20, 2026 04:34
guybedford
force-pushed
the
gbedford/callback-form
branch
from
October 20, 2026 04:34
1ca7889 to
a99adc5
Compare
guybedford
removed this pull request from stack #28023
October 20, 2026 04:42
guybedford
added this pull request to stack #28024
October 20, 2026 04:42
This branch has not been deployed
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.
Adds the
_callbackvariant alongside the_promisevariant of #27880, so the result of an asynchronous JS library function can be delivered to a C callback on the calling thread without a promise handle.foo_callback(args..., callback, arg), listed as__async: ['callback'], runs the same body (withsyncalways false) and callscallback(err, result, arg)once the result is available (NULLfor avoidfunction), witherrset (andresultNULL) if the body's Promise rejects or the main thread exits before completing it. Delivery is always after the call has returned, including for a synchronous completion, and a pending callback holds the runtime alive like a timer. On the main thread the body's value or Promise is settled with.thenundercallUserCallback. From a pthread it isemscripten_proxy_callback_with_ctxof the main-thread body: the result rides in the proxied call'sargas for_promise, and the callback runs as a task on the pthread's proxying queue, so no Promise object or handle exists on that thread and a C event loop can collect it from its own queue processing. As with_promise, the variant is emitted only where used.Tests:
jslib.test_jslib_async_auto_variants_callbackin plain, ASYNCIFY, JSPI andPROXY_TO_PTHREADbuilds, wasm32 and wasm64.Made with AI assistance under my review