File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,16 @@ provided by AsyncHooks itself. The logging should then be skipped when
131131it was the logging itself that caused AsyncHooks callback to call. By
132132doing 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
Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments