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 <[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]>
  • Loading branch information
elliotgoodrich authored and aduh95 committed Jul 16, 2024
1 parent 664bf6c commit d224e9e
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 @@ -327,6 +327,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 @@ -347,6 +348,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 @@ -439,6 +441,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 @@ -461,6 +464,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 d224e9e

Please sign in to comment.