mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
async_hooks: remove experimental onPropagate option
The `onPropagate` option for `AsyncLocalStorage` is problematic for a couple of reasons: 1. It is not expected to be forwards compatible in any way with the upcoming TC-39 `AsyncContext` proposal. 2. It introduces a non-trivial O(n) cost invoking a JavaScript callback for *every* AsyncResource that is created, including every Promise. While it is still experimental, I recommend removing it while we can revisit the fundamental use cases in light of the coming `AsyncContext` proposal. Refs: https://github.com/nodejs/node/issues/46374 PR-URL: https://github.com/nodejs/node/pull/46386 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
parent
088e470dcd
commit
dc90810f9f
3 changed files with 6 additions and 79 deletions
|
@ -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');
|
||||
|
@ -275,17 +274,9 @@ const storageHook = createHook({
|
|||
});
|
||||
|
||||
class AsyncLocalStorage {
|
||||
constructor(options = kEmptyObject) {
|
||||
validateObject(options, 'options');
|
||||
|
||||
const { onPropagate = null } = options;
|
||||
if (onPropagate !== null) {
|
||||
validateFunction(onPropagate, 'options.onPropagate');
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.kResourceStore = Symbol('kResourceStore');
|
||||
this.enabled = false;
|
||||
this._onPropagate = onPropagate;
|
||||
}
|
||||
|
||||
disable() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue