Skip to content

Commit

Permalink
worker: linted code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed Jun 22, 2024
1 parent 4bece45 commit 6cf8158
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions doc/api/worker_threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,20 @@ Establishes a connection to another worker thread in the same process, returning
The target thread must have a connection listener setup via [`worker.setConnectionsListener()`][]
otherwise the connection request will fail.

This method should be used when the target thread is not the direct parent or children of the current thread.
The example below creates 10 nested threads, the last one will try to communicate with the third one.
This method does not support transferables in the `data` argument. If there is need to
transfer objects between threads it can be accomplished via the returned port once the
connection has been established.

This method should be used when the target thread is not the direct
parent or children of the current thread.
If the two threads are parent-children, use the [`require('node:worker_threads').parentPort.postMessage()`][]
and the [`worker.postMessage()`][] to let the threads communicate.

If the messages never need transferable, use `BroadcastChannel` for the communication,
using unique topic ids to mimic a 1-1 channel.

The example below shows the combined use of `connect` and [`worker.setConnectionsListener()`][]:
it creates 10 nested threads, the last one will try to communicate with the third one.

```mjs
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -447,8 +459,8 @@ added: REPLACEME
* `port` {MessagePort} The port than can be used to communicate with the other thread.
* `data` {any} The data passed as second argument to [`worker.connect()`][].
The function must return `true` to accept the connection or any other value to
refuse the connection. If the function returns a `Promise`, it will be awaited.
The function must return `true` to accept the connection or any other value to
refuse the connection. If the function returns a `Promise`, it will be awaited.
Sets the callback that handles connection from other worker threads in the same process.
If the callback is `null` or `undefined` then the current listener is removed.
Expand Down
2 changes: 1 addition & 1 deletion src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ void SendToWorker(const FunctionCallbackInfo<Value>& args) {
// Not all messages require a transfer_list
if (args.Length() > 2) {
if (!GetTransferList(env, context, args[2], &transfer_list)) {
THROW_ERR_INVALID_ARG_TYPE(isolate, "Invalid transfer list");
THROW_ERR_INVALID_ARG_TYPE(isolate, "Invalid transfer list");
return;
}
}
Expand Down

0 comments on commit 6cf8158

Please sign in to comment.