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