mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 12:25:12 +00:00
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: https://github.com/nodejs/node/issues/52846 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
c1dc307221
commit
dda30f972a
@ -327,6 +327,7 @@ const { port1, port2 } = new MessageChannel();
|
|||||||
port1.on('message', (msg) => {
|
port1.on('message', (msg) => {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
});
|
});
|
||||||
|
port1.unref();
|
||||||
|
|
||||||
register('./my-hooks.mjs', {
|
register('./my-hooks.mjs', {
|
||||||
parentURL: import.meta.url,
|
parentURL: import.meta.url,
|
||||||
@ -347,6 +348,7 @@ const { port1, port2 } = new MessageChannel();
|
|||||||
port1.on('message', (msg) => {
|
port1.on('message', (msg) => {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
});
|
});
|
||||||
|
port1.unref();
|
||||||
|
|
||||||
register('./my-hooks.mjs', {
|
register('./my-hooks.mjs', {
|
||||||
parentURL: pathToFileURL(__filename),
|
parentURL: pathToFileURL(__filename),
|
||||||
@ -439,6 +441,7 @@ const { port1, port2 } = new MessageChannel();
|
|||||||
port1.on('message', (msg) => {
|
port1.on('message', (msg) => {
|
||||||
assert.strictEqual(msg, 'increment: 2');
|
assert.strictEqual(msg, 'increment: 2');
|
||||||
});
|
});
|
||||||
|
port1.unref();
|
||||||
|
|
||||||
register('./path-to-my-hooks.js', {
|
register('./path-to-my-hooks.js', {
|
||||||
parentURL: import.meta.url,
|
parentURL: import.meta.url,
|
||||||
@ -461,6 +464,7 @@ const { port1, port2 } = new MessageChannel();
|
|||||||
port1.on('message', (msg) => {
|
port1.on('message', (msg) => {
|
||||||
assert.strictEqual(msg, 'increment: 2');
|
assert.strictEqual(msg, 'increment: 2');
|
||||||
});
|
});
|
||||||
|
port1.unref();
|
||||||
|
|
||||||
register('./path-to-my-hooks.js', {
|
register('./path-to-my-hooks.js', {
|
||||||
parentURL: pathToFileURL(__filename),
|
parentURL: pathToFileURL(__filename),
|
||||||
|
Loading…
Reference in New Issue
Block a user