Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf61d97

Browse filesBrowse files
committed
async_hooks: make sure .{en|dis}able() === this
Make sure that `hook.enable()` and `hook.disable()` return `hook` consistently, as the documentation indicates. PR-URL: #13418 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 85cac4e commit bf61d97
Copy full SHA for bf61d97

File tree

Expand file treeCollapse file tree

2 files changed

+22
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-2
lines changed
Open diff view settings
Collapse file

‎lib/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/async_hooks.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AsyncHook {
9696

9797
// Each hook is only allowed to be added once.
9898
if (hooks_array.includes(this))
99-
return;
99+
return this;
100100

101101
if (!setupHooksCalled) {
102102
setupHooksCalled = true;
@@ -124,7 +124,7 @@ class AsyncHook {
124124

125125
const index = hooks_array.indexOf(this);
126126
if (index === -1)
127-
return;
127+
return this;
128128

129129
hook_fields[kInit] -= +!!this[init_symbol];
130130
hook_fields[kBefore] -= +!!this[before_symbol];
Collapse file
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const async_hooks = require('async_hooks');
5+
6+
const hook = async_hooks.createHook({
7+
init: common.mustCall(() => {}, 1),
8+
before: common.mustNotCall(),
9+
after: common.mustNotCall(),
10+
destroy: common.mustNotCall()
11+
});
12+
13+
assert.strictEqual(hook.enable(), hook);
14+
assert.strictEqual(hook.enable(), hook);
15+
16+
setImmediate(common.mustCall());
17+
18+
assert.strictEqual(hook.disable(), hook);
19+
assert.strictEqual(hook.disable(), hook);
20+
assert.strictEqual(hook.disable(), hook);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.