@@ -99,7 +99,6 @@ added: v20.6.0
99
99
[` initialize` ][] hook.
100
100
* ` transferList` {Object\[ ]} [transferrable objects][] to be passed into the
101
101
` initialize` hook.
102
- * Returns: {any} returns whatever was returned by the ` initialize` hook.
103
102
104
103
Register a module that exports [hooks][] that customize Node.js module
105
104
resolution and loading behavior. See [Customization hooks][].
@@ -348,7 +347,7 @@ names and signatures, and they must be exported as named exports.
348
347
349
348
` ` ` mjs
350
349
export async function initialize ({ number, port }) {
351
- // Receive data from `register`, return data to `register`.
350
+ // Receives data from `register`.
352
351
}
353
352
354
353
export async function resolve (specifier , context , nextResolve ) {
@@ -386,20 +385,15 @@ added: v20.6.0
386
385
> Stability: 1.1 - Active development
387
386
388
387
* ` data` {any} The data from ` register (loader, import .meta.url, { data })` .
389
- * Returns: {any} The data to be returned to the caller of ` register` .
390
388
391
389
The ` initialize` hook provides a way to define a custom function that runs in
392
390
the hooks thread when the hooks module is initialized. Initialization happens
393
391
when the hooks module is registered via [` register` ][].
394
392
395
- This hook can send and receive data from a [` register` ][] invocation, including
396
- ports and other transferrable objects. The return value of ` initialize` must be
397
- either:
398
-
399
- * ` undefined` ,
400
- * something that can be posted as a message between threads (e.g. the input to
401
- [` port.postMessage` ][]),
402
- * a ` Promise` resolving to one of the aforementioned values.
393
+ This hook can receive data from a [` register` ][] invocation, including
394
+ ports and other transferrable objects. The return value of ` initialize` can be a
395
+ {Promise}, in which case it will be awaited before the main application thread
396
+ execution resumes.
403
397
404
398
Module customization code:
405
399
@@ -408,7 +402,6 @@ Module customization code:
408
402
409
403
export async function initialize ({ number, port }) {
410
404
port .postMessage (` increment: ${ number + 1 } ` );
411
- return ' ok' ;
412
405
}
413
406
` ` `
414
407
@@ -428,13 +421,11 @@ port1.on('message', (msg) => {
428
421
assert .strictEqual (msg, ' increment: 2' );
429
422
});
430
423
431
- const result = register (' ./path-to-my-hooks.js' , {
424
+ register (' ./path-to-my-hooks.js' , {
432
425
parentURL: import .meta.url,
433
426
data: { number: 1 , port: port2 },
434
427
transferList: [port2],
435
428
});
436
-
437
- assert .strictEqual (result, ' ok' );
438
429
` ` `
439
430
440
431
` ` ` cjs
@@ -452,13 +443,11 @@ port1.on('message', (msg) => {
452
443
assert .strictEqual (msg, ' increment: 2' );
453
444
});
454
445
455
- const result = register (' ./path-to-my-hooks.js' , {
446
+ register (' ./path-to-my-hooks.js' , {
456
447
parentURL: pathToFileURL (__filename ),
457
448
data: { number: 1 , port: port2 },
458
449
transferList: [port2],
459
450
});
460
-
461
- assert .strictEqual (result, ' ok' );
462
451
` ` `
463
452
464
453
#### ` resolve (specifier, context, nextResolve)`
@@ -1116,7 +1105,6 @@ returned object contains the following keys:
1116
1105
[` Uint8Array ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
1117
1106
[` initialize` ]: #initialize
1118
1107
[` module ` ]: modules.md#the-module-object
1119
- [` port .postMessage ` ]: worker_threads.md#portpostmessagevalue-transferlist
1120
1108
[` port .ref ()` ]: worker_threads.md#portref
1121
1109
[` port .unref ()` ]: worker_threads.md#portunref
1122
1110
[` register` ]: #moduleregisterspecifier-parenturl-options
0 commit comments