diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index ead62be01d4e59..09d22c9fbee592 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -783,7 +783,7 @@ code modification is necessary if that is done. ### DEP0085: AsyncHooks Sensitive API -Type: Runtime +Type: End-of-Life The AsyncHooks Sensitive API was never documented and had various of minor issues, see https://github.com/nodejs/node/issues/15572. Use the `AsyncResource` @@ -793,7 +793,7 @@ API instead. ### DEP0086: Remove runInAsyncIdScope -Type: Runtime +Type: End-of-Life `runInAsyncIdScope` doesn't emit the `before` or `after` event and can thus cause a lot of issues. See https://github.com/nodejs/node/issues/14328 for more diff --git a/lib/async_hooks.js b/lib/async_hooks.js index 78dff7218c13ea..cf3a40c1274a14 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -1,14 +1,10 @@ 'use strict'; const errors = require('internal/errors'); -const internalUtil = require('internal/util'); const async_wrap = process.binding('async_wrap'); const internal_async_hooks = require('internal/async_hooks'); // Get functions -// Only used to support a deprecated API. pushAsyncIds, popAsyncIds should -// never be directly in this manner. -const { pushAsyncIds, popAsyncIds } = async_wrap; // For userland AsyncResources, make sure to emit a destroy event when the // resource gets gced. const { registerDestroyHook } = async_wrap; @@ -17,10 +13,9 @@ const { getHookArrays, enableHooks, disableHooks, - // Sensitive Embedder API + // Internal Embedder API newUid, initTriggerId, - setInitTriggerId, emitInit, emitBefore, emitAfter, @@ -204,18 +199,6 @@ class AsyncResource { } -function runInAsyncIdScope(asyncId, cb) { - // Store the async id now to make sure the stack is still good when the ids - // are popped off the stack. - const prevId = executionAsyncId(); - pushAsyncIds(asyncId, prevId); - try { - cb(); - } finally { - popAsyncIds(asyncId); - } -} - // Placing all exports down here because the exported classes won't export // otherwise. module.exports = { @@ -226,61 +209,3 @@ module.exports = { // Embedder API AsyncResource, }; - -// Deprecated API // - -Object.defineProperty(module.exports, 'runInAsyncIdScope', { - get: internalUtil.deprecate(function() { - return runInAsyncIdScope; - }, 'async_hooks.runInAsyncIdScope is deprecated. ' + - 'Create an AsyncResource instead.', 'DEP0086') -}); - -Object.defineProperty(module.exports, 'newUid', { - get: internalUtil.deprecate(function() { - return newUid; - }, 'async_hooks.newUid is deprecated. ' + - 'Use AsyncResource instead.', 'DEP0085') -}); - -Object.defineProperty(module.exports, 'initTriggerId', { - get: internalUtil.deprecate(function() { - return initTriggerId; - }, 'async_hooks.initTriggerId is deprecated. ' + - 'Use the AsyncResource default instead.', 'DEP0085') -}); - -Object.defineProperty(module.exports, 'setInitTriggerId', { - get: internalUtil.deprecate(function() { - return setInitTriggerId; - }, 'async_hooks.setInitTriggerId is deprecated. ' + - 'Use the triggerAsyncId parameter in AsyncResource instead.', 'DEP0085') -}); - -Object.defineProperty(module.exports, 'emitInit', { - get: internalUtil.deprecate(function() { - return emitInit; - }, 'async_hooks.emitInit is deprecated. ' + - 'Use AsyncResource constructor instead.', 'DEP0085') -}); - -Object.defineProperty(module.exports, 'emitBefore', { - get: internalUtil.deprecate(function() { - return emitBefore; - }, 'async_hooks.emitBefore is deprecated. ' + - 'Use AsyncResource.emitBefore instead.', 'DEP0085') -}); - -Object.defineProperty(module.exports, 'emitAfter', { - get: internalUtil.deprecate(function() { - return emitAfter; - }, 'async_hooks.emitAfter is deprecated. ' + - 'Use AsyncResource.emitAfter instead.', 'DEP0085') -}); - -Object.defineProperty(module.exports, 'emitDestroy', { - get: internalUtil.deprecate(function() { - return emitDestroy; - }, 'async_hooks.emitDestroy is deprecated. ' + - 'Use AsyncResource.emitDestroy instead.', 'DEP0085') -}); diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 5964a847fc0a25..002cbccb03218b 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -236,7 +236,7 @@ function disableHooks() { async_hook_fields[kCheck] -= 1; } -// Sensitive Embedder API // +// Internal Embedder API // // Increment the internal id counter and return the value. Important that the // counter increment first. Since it's done the same way in @@ -338,7 +338,7 @@ module.exports = { }, enableHooks, disableHooks, - // Sensitive Embedder API + // Internal Embedder API newUid, initTriggerId, setInitTriggerId, diff --git a/test/async-hooks/test-no-assert-when-disabled.js b/test/async-hooks/test-no-assert-when-disabled.js index 47aafe52c35d8d..1d26897ab05225 100644 --- a/test/async-hooks/test-no-assert-when-disabled.js +++ b/test/async-hooks/test-no-assert-when-disabled.js @@ -2,7 +2,7 @@ // Flags: --no-force-async-hooks-checks --expose-internals const common = require('../common'); -const async_hooks = require('async_hooks'); +const async_hooks = require('internal/async_hooks'); const internal = require('internal/process/next_tick'); // Using undefined as the triggerAsyncId. diff --git a/test/parallel/test-async-hooks-run-in-async-id-scope.js b/test/parallel/test-async-hooks-run-in-async-id-scope.js deleted file mode 100644 index 14d1c7423fcf29..00000000000000 --- a/test/parallel/test-async-hooks-run-in-async-id-scope.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const async_hooks = require('async_hooks'); - -const asyncId = new async_hooks.AsyncResource('test').asyncId(); - -assert.notStrictEqual(async_hooks.executionAsyncId(), asyncId); - -async_hooks.runInAsyncIdScope(asyncId, common.mustCall(() => { - assert.strictEqual(async_hooks.executionAsyncId(), asyncId); -}));