From e0d213df2b158db4458a4f1d90811d4a3c8ad925 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 d59726a7d53a24..f2dddeab1d3186 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -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, @@ -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), @@ -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, @@ -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),