Hyper Minimalistic Spec - Unopinionated Async ContextΒ #110
Description
I am nobody and this is going to be a bit brutal lol π³οΈ Please bear with me π.
What if we remove almost everything from the proposal and keep the strict minimum when it comes to the API.
There is a lot of opinions about what should the feature look like.
But in reality, the only thing that is needed, to implement almost all proposed features, is a very simple API that should provide:
- Ability to know in which context the code is in from the JS code.
- Ability to walk the "async stack" upward from the JS code.
// Just an example API using getters
const stack = AsyncContext.current; // <- How to get the current stack object.
stack.origin.origin.origin.origin // <- How to traverse the stack from "async stack" to "async stack".
These two features alone allows to implement everything else. That will allow library developers to build their own API on top of it to satifies different kind of constraints, objectives or opinions.
Note: this would have advantage to have a zero performance cost on the native side (If I'm not mistaken), since the engine already knows where to forward errors in an async call, it could repurpose the same code to surface the current async context using getters from the JS land.
Note2: I refactored the polyfill I created to showcase exactly that: https://github.com/iliasbhal/simple-async-context
Let me know what you think π