Skip to content
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

Initial spec draft #28

Merged
merged 6 commits into from
Mar 8, 2023
Merged

Initial spec draft #28

merged 6 commits into from
Mar 8, 2023

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Mar 1, 2023

This is the initial spec draft of the proposal. It follows the (tentative) idea of:

  1. The async context storage is a per-agent setting.
  2. Specifying unhandledrejection behavior #16: HostPromiseRejectionTracker is called in the context at the time of the promise's rejection.

@legendecas legendecas requested a review from jridgewell March 1, 2023 07:10
Enables biblio and spec linting
ome small grammar changes, reusing `AsyncContextSnapshot()`, simplifying `AsyncContextSnapshot()`, simplifying `AsyncContext.prototype.run()`.
Copy link
Member

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed some changes:

  • Minor grammar updates
  • Simplified AsyncContextSnapshot() to just return a reference to the current
  • Changed AsyncContext.p.run() to create a cloned mapping
  • Small updates to the spec steps

spec.html Show resolved Hide resolved
</ul>

<emu-clause id="sec-asynccontext">
<h1>AsyncContext ( )</h1>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about 2 extensions to the constructor:

  1. A name string
  2. A defaultValue value

The name string is intended to aid debugging in dev-tools. I imagine they might want to display the global context mapping, and it'd be more helpful if we could annotate that list in some way. This could be stored on the symbol's description.

The defaultValue would be returned instead of undefined whenever the context hasn't been run in this call stack. This is sometimes useful in React.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added name as the first argument.

However, I'd find defaultValue can be a foot gun as it may return the same reference to a single object and it may be mistakenly modified. A function returning a default value might be a better choice here.

spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated
@@ -366,13 +371,14 @@ <h1>The AsyncContext Constructor</h1>
</ul>

<emu-clause id="sec-asynccontext">
<h1>AsyncContext ( )</h1>
<h1>AsyncContext ( _name_ )</h1>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we should bring this up in committee and add it to the spec afterwards. That with the defaultValue API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed and opened an issue to track it: #29.

@legendecas legendecas merged commit 9d3868d into master Mar 8, 2023
@legendecas legendecas deleted the spec branch March 8, 2023 02:12
@kamilogorek
Copy link
Member

Is there a way to see a pretty-rendered version of the current spec?

@legendecas
Copy link
Member Author

Please check out https://tc39.es/proposal-async-context/ for rendered version.

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