Skip to content

Commit 6cf8158

Browse files
committed
worker: linted code
1 parent 4bece45 commit 6cf8158

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

doc/api/worker_threads.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,20 @@ Establishes a connection to another worker thread in the same process, returning
8383
The target thread must have a connection listener setup via [`worker.setConnectionsListener()`][]
8484
otherwise 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
90102
import { 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
453465
Sets the callback that handles connection from other worker threads in the same process.
454466
If the callback is `null` or `undefined` then the current listener is removed.

src/node_worker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ void SendToWorker(const FunctionCallbackInfo<Value>& args) {
979979
// Not all messages require a transfer_list
980980
if (args.Length() > 2) {
981981
if (!GetTransferList(env, context, args[2], &transfer_list)) {
982-
THROW_ERR_INVALID_ARG_TYPE(isolate, "Invalid transfer list");
982+
THROW_ERR_INVALID_ARG_TYPE(isolate, "Invalid transfer list");
983983
return;
984984
}
985985
}

0 commit comments

Comments
 (0)