Skip to content

Commit e0d213d

Browse files
elliotgoodrichmarco-ippolito
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 <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
1 parent 2d8490f commit e0d213d

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
@@ -321,6 +321,7 @@ const { port1, port2 } = new MessageChannel();
321321
port1.on('message', (msg) => {
322322
console.log(msg);
323323
});
324+
port1.unref();
324325

325326
register('./my-hooks.mjs', {
326327
parentURL: import.meta.url,
@@ -341,6 +342,7 @@ const { port1, port2 } = new MessageChannel();
341342
port1.on('message', (msg) => {
342343
console.log(msg);
343344
});
345+
port1.unref();
344346

345347
register('./my-hooks.mjs', {
346348
parentURL: pathToFileURL(__filename),
@@ -431,6 +433,7 @@ const { port1, port2 } = new MessageChannel();
431433
port1.on('message', (msg) => {
432434
assert.strictEqual(msg, 'increment: 2');
433435
});
436+
port1.unref();
434437

435438
register('./path-to-my-hooks.js', {
436439
parentURL: import.meta.url,
@@ -453,6 +456,7 @@ const { port1, port2 } = new MessageChannel();
453456
port1.on('message', (msg) => {
454457
assert.strictEqual(msg, 'increment: 2');
455458
});
459+
port1.unref();
456460

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

0 commit comments

Comments
 (0)