Skip to content

Commit

Permalink
doc: fix module customization hook examples
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
elliotgoodrich authored and marco-ippolito committed Aug 19, 2024
1 parent 2d8490f commit e0d213d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ const { port1, port2 } = new MessageChannel();
port1.on('message', (msg) => {
console.log(msg);
});
port1.unref();

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

register('./my-hooks.mjs', {
parentURL: pathToFileURL(__filename),
Expand Down Expand Up @@ -431,6 +433,7 @@ const { port1, port2 } = new MessageChannel();
port1.on('message', (msg) => {
assert.strictEqual(msg, 'increment: 2');
});
port1.unref();

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

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

0 comments on commit e0d213d

Please sign in to comment.