@@ -136,6 +136,56 @@ changes:
136136Creates a new instance of ` AsyncLocalStorage ` . Store is only provided within a
137137` run() ` call or after an ` enterWith() ` call.
138138
139+ ### Static method: ` AsyncLocalStorage.bind(fn) `
140+
141+ <!-- YAML
142+ added: REPLACEME
143+ -->
144+
145+ > Stability: 1 - Experimental
146+
147+ * ` fn ` {Function} The function to bind to the current execution context.
148+ * Returns: {Function} A new function that calls ` fn ` within the captured
149+ execution context.
150+
151+ Binds the given function to the current execution context.
152+
153+ ### Static method: ` AsyncLocalStorage.snapshot() `
154+
155+ <!-- YAML
156+ added: REPLACEME
157+ -->
158+
159+ > Stability: 1 - Experimental
160+
161+ * Returns: {Function} A new function with the signature
162+ ` (fn: (...args) : R, ...args) : R ` .
163+
164+ Captures the current execution context and returns a function that accepts a
165+ function as an argument. Whenever the returned function is called, it
166+ calls the function passed to it within the captured context.
167+
168+ ``` js
169+ const asyncLocalStorage = new AsyncLocalStorage ();
170+ const runInAsyncScope = asyncLocalStorage .run (123 , () => asyncLocalStorage .snapshot ());
171+ const result = asyncLocalStorage .run (321 , () => runInAsyncScope (() => asyncLocalStorage .getStore ()));
172+ console .log (result); // returns 123
173+ ```
174+
175+ AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
176+ async context tracking purposes, for example:
177+
178+ ``` js
179+ class Foo {
180+ #runInAsyncScope = AsyncLocalStorage .snapshot ();
181+
182+ get () { return this .#runInAsyncScope (() => asyncLocalStorage .getStore ()); }
183+ }
184+
185+ const foo = asyncLocalStorage .run (123 , () => new Foo ());
186+ console .log (asyncLocalStorage .run (321 , () => foo .get ())); // returns 123
187+ ```
188+
139189### ` asyncLocalStorage.disable() `
140190
141191<!-- YAML
0 commit comments