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

async_hooks: remove experimental onPropagate option #46386

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 4 additions & 16 deletions doc/api/async_context.md
Expand Up @@ -116,37 +116,26 @@ Each instance of `AsyncLocalStorage` maintains an independent storage context.
Multiple instances can safely exist simultaneously without risk of interfering
with each other's data.

### `new AsyncLocalStorage([options])`
### `new AsyncLocalStorage()`

<!-- YAML
added:
- v13.10.0
- v12.17.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/46386
description: Removed experimental onPropagate option.
- version:
- v19.2.0
- v18.13.0
pr-url: https://github.com/nodejs/node/pull/45386
description: Add option onPropagate.
-->

> Stability: 1 - `options.onPropagate` is experimental.

* `options` {Object}
* `onPropagate` {Function} Optional callback invoked before a store is
propagated to a new async resource. Returning `true` allows propagation,
returning `false` avoids it. Default is to propagate always.

Creates a new instance of `AsyncLocalStorage`. Store is only provided within a
`run()` call or after an `enterWith()` call.

The `onPropagate` is called during creation of an async resource. Throwing at
this time will print the stack trace and exit. See
[`async_hooks` Error handling][] for details.

Creating an async resource within the `onPropagate` callback will result in
a recursive call to `onPropagate`.

### `asyncLocalStorage.disable()`

<!-- YAML
Expand Down Expand Up @@ -836,5 +825,4 @@ const server = createServer((req, res) => {
[`EventEmitter`]: events.md#class-eventemitter
[`Stream`]: stream.md#stream
[`Worker`]: worker_threads.md#class-worker
[`async_hooks` Error handling]: async_hooks.md#error-handling
[`util.promisify()`]: util.md#utilpromisifyoriginal
15 changes: 2 additions & 13 deletions lib/async_hooks.js
Expand Up @@ -23,7 +23,6 @@ const {
const { kEmptyObject } = require('internal/util');
const {
validateFunction,
validateObject,
validateString,
} = require('internal/validators');
const internal_async_hooks = require('internal/async_hooks');
Expand Down Expand Up @@ -275,17 +274,9 @@ const storageHook = createHook({
});

class AsyncLocalStorage {
constructor(options = kEmptyObject) {
validateObject(options, 'options');
jasnell marked this conversation as resolved.
Show resolved Hide resolved

const { onPropagate = null } = options;
if (onPropagate !== null) {
validateFunction(onPropagate, 'options.onPropagate');
}

constructor() {
this.kResourceStore = Symbol('kResourceStore');
this.enabled = false;
this._onPropagate = onPropagate;
}

disable() {
Expand All @@ -312,9 +303,7 @@ class AsyncLocalStorage {
_propagate(resource, triggerResource, type) {
const store = triggerResource[this.kResourceStore];
if (this.enabled) {
if (this._onPropagate === null || this._onPropagate(type, store)) {
resource[this.kResourceStore] = store;
}
resource[this.kResourceStore] = store;
}
}

Expand Down
50 changes: 0 additions & 50 deletions test/async-hooks/test-async-local-storage-stop-propagation.js

This file was deleted.