diff --git a/doc/api/async_context.md b/doc/api/async_context.md index 9f60071a044196..267fc207a1478f 100644 --- a/doc/api/async_context.md +++ b/doc/api/async_context.md @@ -215,7 +215,7 @@ added: - v12.17.0 --> -> Stability: 1 - Experimental +> Stability: 2 - Stable Disables the instance of `AsyncLocalStorage`. All subsequent calls to `asyncLocalStorage.getStore()` will return `undefined` until @@ -255,7 +255,7 @@ added: - v12.17.0 --> -> Stability: 1 - Experimental +> Stability: 2 - Stable * `store` {any} diff --git a/lib/internal/async_local_storage/async_context_frame.js b/lib/internal/async_local_storage/async_context_frame.js index 518e955379ac54..fade26b353c564 100644 --- a/lib/internal/async_local_storage/async_context_frame.js +++ b/lib/internal/async_local_storage/async_context_frame.js @@ -48,6 +48,17 @@ class AsyncLocalStorage { AsyncContextFrame.disable(this); } + unNamedMethod(store) { + const self = this; + this.enterWith(store); + return { + [Symbol.dispose]() { + console.log('Stop propagating store', store); + self.disable(); + } + } + } + enterWith(data) { const frame = new AsyncContextFrame(this, data); AsyncContextFrame.set(frame); diff --git a/lib/internal/async_local_storage/async_hooks.js b/lib/internal/async_local_storage/async_hooks.js index d227549412bf61..118e9b78f75454 100644 --- a/lib/internal/async_local_storage/async_hooks.js +++ b/lib/internal/async_local_storage/async_hooks.js @@ -94,6 +94,17 @@ class AsyncLocalStorage { } } + unNamedMethod(store) { + const self = this; + this.enterWith(store); + return { + [Symbol.dispose]() { + console.log('Stop propagating store', resource[self.kResourceStore]); + self.disable(); + } + } + } + enterWith(store) { this._enable(); const resource = executionAsyncResource();