Skip to content

Commit 131639a

Browse files
elliotgoodrichaduh95
authored andcommitted
doc: fix module customization hook examples
When running these examples, `node` fails to return as this `MessagePort` keeps the event loop active in the main thread unless it is `unref()`ed. Fixes: #52846 PR-URL: #53637 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Ulises Gascón <[email protected]>
1 parent 53e2d68 commit 131639a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

doc/api/module.md

+4
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ const { port1, port2 } = new MessageChannel();
327327
port1.on('message', (msg) => {
328328
console.log(msg);
329329
});
330+
port1.unref();
330331

331332
register('./my-hooks.mjs', {
332333
parentURL: import.meta.url,
@@ -347,6 +348,7 @@ const { port1, port2 } = new MessageChannel();
347348
port1.on('message', (msg) => {
348349
console.log(msg);
349350
});
351+
port1.unref();
350352

351353
register('./my-hooks.mjs', {
352354
parentURL: pathToFileURL(__filename),
@@ -439,6 +441,7 @@ const { port1, port2 } = new MessageChannel();
439441
port1.on('message', (msg) => {
440442
assert.strictEqual(msg, 'increment: 2');
441443
});
444+
port1.unref();
442445

443446
register('./path-to-my-hooks.js', {
444447
parentURL: import.meta.url,
@@ -461,6 +464,7 @@ const { port1, port2 } = new MessageChannel();
461464
port1.on('message', (msg) => {
462465
assert.strictEqual(msg, 'increment: 2');
463466
});
467+
port1.unref();
464468

465469
register('./path-to-my-hooks.js', {
466470
parentURL: pathToFileURL(__filename),

0 commit comments

Comments
 (0)