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 deprecated API #17147

Closed
wants to merge 2 commits into from
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ code modification is necessary if that is done.
<a id="DEP0085"></a>
### 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:/nodejs/node/issues/15572. Use the `AsyncResource`
Expand All @@ -793,7 +793,7 @@ API instead.
<a id="DEP0086"></a>
### 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:/nodejs/node/issues/14328 for more
Expand Down
77 changes: 1 addition & 76 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,10 +13,9 @@ const {
getHookArrays,
enableHooks,
disableHooks,
// Sensitive Embedder API
// Internal Embedder API
newUid,
initTriggerId,
setInitTriggerId,
emitInit,
emitBefore,
emitAfter,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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')
});
4 changes: 2 additions & 2 deletions lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -338,7 +338,7 @@ module.exports = {
},
enableHooks,
disableHooks,
// Sensitive Embedder API
// Internal Embedder API
newUid,
initTriggerId,
setInitTriggerId,
Expand Down
2 changes: 1 addition & 1 deletion test/async-hooks/test-no-assert-when-disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 0 additions & 13 deletions test/parallel/test-async-hooks-run-in-async-id-scope.js

This file was deleted.