Skip to content

Commit bf61d97

Browse files
committedJun 10, 2017
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

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎lib/async_hooks.js

+2-2
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];
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)