Skip to content

Commit 65b17b9

Browse files
committed
test & doc
1 parent df0a172 commit 65b17b9

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

doc/api/async_hooks.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ provided by AsyncHooks itself. The logging should then be skipped when
131131
it was the logging itself that caused AsyncHooks callback to call. By
132132
doing this the otherwise infinite recursion is broken.
133133

134+
#### `async_hooks.getTypes()`
135+
136+
<!-- YAML
137+
added: REPLACEME
138+
-->
139+
140+
* Returns: `{Array}` list of async resource type names
141+
142+
Return the list of async resource type names. Names are simple strings.
143+
134144
#### `asyncHook.enable()`
135145

136146
* Returns {AsyncHook} A reference to `asyncHook`.
@@ -428,6 +438,13 @@ const server = net.createServer(function onConnection(conn) {
428438
});
429439
```
430440

441+
#### `async_hooks.registerTypeName(type)`
442+
443+
* `type` {string} a new type of async resource
444+
* Returns {string} the type name to use
445+
446+
Registers the type name for a new async resource.
447+
431448
#### `async_hooks.triggerId()`
432449

433450
* Returns {number} the ID of the resource responsible for calling the callback
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const async_hooks = require('async_hooks');
5+
6+
const types1 = async_hooks.getTypes();
7+
types1.forEach((v, k) => assert.strictEqual(
8+
typeof v,
9+
'string',
10+
`${v} from types[${k}] should be a string`)
11+
);
12+
13+
const sillyName = 'gaga';
14+
const newType = async_hooks.getTypes(sillyName);
15+
assert.strictEqual(
16+
typeof newType,
17+
'string',
18+
`${newType} should be a string`
19+
);
20+
assert.strictEqual(newType, sillyName);
21+
22+
assert.throws(() => async_hooks.getTypes(sillyName),
23+
common.expectsError(
24+
'ERR_ASYNC_PROVIDER_NAME',
25+
TypeError,
26+
`${sillyName} type name already registered`
27+
));
28+
29+
const types2 = async_hooks.getTypes();
30+
assert.strictEqual(types2.length, types1 + 1);
31+
assert.strictEqual(types2.includes(newType), true);

0 commit comments

Comments
 (0)