html
html copied to clipboard
TC39 AsyncContext Integration
What problem are you trying to solve?
TC39 stage 2 proposal AsyncContext adds new built-in APIs to propagate data through logically-connected sync/async code execution. It will need HTML/Web API integration to properly save and restore context data at the boundary of asynchronous call contexts, e.g. timers, event listeners, and observers.
- [ ] Define specification infrastructure
- [ ] ...
What solutions exist today?
The solution is not yet complete, submitting this proposal to open a space for discussion in HTML.
How would you solve it?
The issue https://github.com/tc39/proposal-async-context/issues/82 has iterated on various integration points that are essential on the web platform.
The biggest thing we need to decide at the HTML level is, for each API which accepts callbacks, which AsyncContext.Snapshot should it be run in. Many of us are leaning towards "the snapshot where the callback-accepting API was first called".
Some Web APIs could benefit from passing an additional AsyncContext.Shapshot instance to the callback, e.g., it might be useful for window.onerror to have access to the current snapshot when the exception was thrown--this could be an attribute attached to the Event, or the Error/DOMException, for example.
Web integration for AsyncContext under discussion at https://github.com/tc39/proposal-async-context/pull/100 .
The basic web integration document PR has been merged: https://github.com/tc39/proposal-async-context/blob/master/WEB-INTEGRATION.md
There's an additional proposed API at tc39/proposal-async-context#107 that isn't yet incorporated into that document because there are still some open questions.
As discussed in the last WHATNOT meeting (https://github.com/whatwg/html/issues/11826#issuecomment-3472399560), the AsyncContext web integration will be running through the WHATWG Stages process, since it is large and complicated enough, and the feedback from implementers and spec editors at each step seems very welcome. Currently the way in which this stages process would interact with TC39's is still to be defined.
The AsyncContext web integration is currently stage 0, with the web integration document at the TC39 repo serving as an explainer.