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
  • Loading branch information
elliotgoodrich committed Jun 29, 2024
1 parent 7771025 commit e61a717
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 e61a717

Please sign in to comment.