From 131639afb78d013811edd9c98202e161c44b066c Mon Sep 17 00:00:00 2001 From: Elliot Goodrich Date: Mon, 1 Jul 2024 14:34:35 +0100 Subject: [PATCH] doc: fix module customization hook examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Chemi Atlow Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Moshe Atlow Reviewed-By: Ulises Gascón --- doc/api/module.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/api/module.md b/doc/api/module.md index be42ca85203d82..730776d984c562 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -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, @@ -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), @@ -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, @@ -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),