@@ -83,8 +83,20 @@ Establishes a connection to another worker thread in the same process, returning
8383The target thread must have a connection listener setup via [ ` worker.setConnectionsListener() ` ] [ ]
8484otherwise the connection request will fail.
8585
86- This method should be used when the target thread is not the direct parent or children of the current thread.
87- The example below creates 10 nested threads, the last one will try to communicate with the third one.
86+ This method does not support transferables in the ` data ` argument. If there is need to
87+ transfer objects between threads it can be accomplished via the returned port once the
88+ connection has been established.
89+
90+ This method should be used when the target thread is not the direct
91+ parent or children of the current thread.
92+ If the two threads are parent-children, use the [ ` require('node:worker_threads').parentPort.postMessage() ` ] [ ]
93+ and the [ ` worker.postMessage() ` ] [ ] to let the threads communicate.
94+
95+ If the messages never need transferable, use ` BroadcastChannel ` for the communication,
96+ using unique topic ids to mimic a 1-1 channel.
97+
98+ The example below shows the combined use of ` connect ` and [ ` worker.setConnectionsListener() ` ] [ ] :
99+ it creates 10 nested threads, the last one will try to communicate with the third one.
88100
89101``` mjs
90102import { fileURLToPath } from ' node:url' ;
@@ -447,8 +459,8 @@ added: REPLACEME
447459 * ` port` {MessagePort} The port than can be used to communicate with the other thread.
448460 * ` data` {any} The data passed as second argument to [` worker .connect ()` ][].
449461
450- The function must return ` true ` to accept the connection or any other value to
451- refuse the connection. If the function returns a ` Promise ` , it will be awaited.
462+ The function must return ` true ` to accept the connection or any other value to
463+ refuse the connection. If the function returns a ` Promise ` , it will be awaited.
452464
453465Sets the callback that handles connection from other worker threads in the same process.
454466If the callback is ` null ` or ` undefined ` then the current listener is removed.
0 commit comments