Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed May 30, 2023
1 parent 6a6be2f commit 8bf37a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ interface AsyncLocalOptions<T> {
class AsyncSnapshot {
constructor();

run<R>(fn: (...args: any[]) => R, ...args: any[]): R;
restore<R>(fn: (...args: any[]) => R, ...args: any[]): R;
}
```

Expand Down Expand Up @@ -225,7 +225,7 @@ function main() {
// The snapshotDuringTop will restore all AsyncLocal to their snapshot
// state and invoke the wrapped function. We pass a function which it will
// invoke.
snapshotDuringTop.run(() => {
snapshotDuringTop.restore(() => {
// Despite being lexically nested inside 'C', the snapshot restored us to
// to the 'top' state.
console.log(local.get()); // => 'top'
Expand All @@ -249,7 +249,7 @@ export function enqueueCallback(cb: () => void) {
// Each callback is stored with the context at which it was enqueued.
const snapshot = new AsyncSnapshot();
queue.push(() => {
snapshot.run(cb);
snapshot.restore(cb);
});
}

Expand Down
25 changes: 13 additions & 12 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1>The Async Context Mapping Record Specification Type</h1>
an AsyncLocal instance
</td>
<td>
The name of the AsyncLocal instance.
The AsyncLocal instance as the key in the mapping.
</td>
</tr>
<tr>
Expand All @@ -51,7 +51,7 @@ <h1>The Async Context Mapping Record Specification Type</h1>
an ECMAScript language value
</td>
<td>
The default value of the AsyncLocal instance when no entry is found in the mapping.
The value of the AsyncLocal instance in the mapping.
</td>
</tr>
</table>
Expand Down Expand Up @@ -122,7 +122,7 @@ <h1>Agents</h1>
<ins>a List of Async Context Mapping Records</ins>
</td>
<td>
<ins>A map from the AsyncContext's key symbol to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]].</ins>
<ins>A map from the AsyncLocal instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]]. The map is initially empty.</ins>
</td>
</tr>
</table>
Expand Down Expand Up @@ -167,7 +167,7 @@ <h1>JobCallback Records</h1>
<ins>a List of Async Context Mapping Records</ins>
</td>
<td>
<ins>A map from the AsyncContext's key symbol to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]].</ins>
<ins>A map from the AsyncLocal instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]].</ins>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -320,8 +320,8 @@ <h1>Properties of the AsyncSnapshot Prototype Object</h1>
<li>does not have any of the other internal slots of AsyncSnapshot instances.</li>
</ul>

<emu-clause id="sec-asyncsnapshot.prototype.run">
<h1>AsyncSnapshot.prototype.run ( _func_, ..._args_ )</h1>
<emu-clause id="sec-asyncsnapshot.prototype.restore">
<h1>AsyncSnapshot.prototype.restore ( _func_, ..._args_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _asyncSnapshot_ be the *this* value.
Expand Down Expand Up @@ -380,7 +380,7 @@ <h1>The AsyncLocal Constructor</h1>
<li>is the initial value of the *"AsyncLocal"* property of the global object.</li>
<li>creates and initializes a new AsyncLocal when called as a constructor.</li>
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
<li>may be used as the value in an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified AsyncLocal behaviour must include a `super` call to the AsyncLocal constructor to create and initialize the subclass instance with the internal state necessary to support the `AsyncLocal` and `AsyncLocal.prototype` built-in methods.</li>
<li>may be used as the value in an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified AsyncLocal behaviour must include a `super` call to the AsyncLocal constructor to create and initialize the subclass instance with the internal state necessary to support the `AsyncLocal.prototype` built-in methods.</li>
</ul>

<emu-clause id="sec-asynclocal">
Expand All @@ -389,13 +389,14 @@ <h1>AsyncLocal ( _options_ )</h1>

<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Let _nameStr_ be the empty String.
1. Let _defaultValue_ be *undefined*.
1. If _options_ is an Object, then
1. Let _name_ be ? Get(_options_, *"name"*).
1. Let _nameStr_ be ? ToString(_name_).
1. Let _namePresent_ be ? HasProperty(_options_, *"name"*).
1. If _namePresent_ is *true*, then
1. Let _name_ be ? Get(_options_, *"name"*).
1. Let _nameStr_ be ? ToString(_name_).
1. Let _defaultValue_ be ? Get(_options_, *"defaultValue"*).
1. Else,
1. Let _nameStr_ be the empty String.
1. Let _defaultValue_ be *undefined*.
1. Let _asyncLocal_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%AsyncLocal.prototype%"*, « [[AsyncLocalName]], [[AsyncLocalDefaultValue]] »).
1. Set _asyncLocal_.[[AsyncLocalName]] to _nameStr_.
1. Set _asyncLocal_.[[AsyncLocalDefaultValue]] to _defaultValue_.
Expand Down

0 comments on commit 8bf37a5

Please sign in to comment.