worker: add name for worker - #59213
Conversation
8cffc77 to
db88135
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59213 +/- ##
==========================================
- Coverage 90.04% 90.00% -0.04%
==========================================
Files 648 649 +1
Lines 191200 192219 +1019
Branches 37472 37659 +187
==========================================
+ Hits 172160 173006 +846
- Misses 11665 11826 +161
- Partials 7375 7387 +12
🚀 New features to boost your workflow:
|
c59afff to
cf60597
Compare
cf60597 to
854c313
Compare
Failed to start CI⚠ Commits were pushed since the last approving review: ⚠ - worker: add name for worker ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/16567111188 |
854c313 to
42df3d9
Compare
|
@addaleax Hi! I modified the test example to support creating worker in worker. Could you help review again ? Thanks ! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
|
||
| const name = 'test-worker-thread-name'; | ||
|
|
||
| if (workerData?.isWorker) { |
There was a problem hiding this comment.
It looks like the workerData?.isWorker is here only to determine if you're running in a worker or not. You can use isMainThread for that purpose and simplify this a bit.
const { Worker, isMainThread } = require('worker_threads');
if (!isMainThread) {
// This is running in a worker
} else {
// This is running in the main thread
}There was a problem hiding this comment.
workerData?.isWorker is designed to support the creation of worker within worker.
There was a problem hiding this comment.
Is that actually necessary tho? I would just make this test as a whole not run in a worker.
There was a problem hiding this comment.
We also need to support this use case, so should we support this kind of test ?
|
|
||
| if (workerData?.isWorker) { | ||
| assert.strictEqual(threadName, name); | ||
| process.exit(0); |
There was a problem hiding this comment.
There should be no reason for process.exit(0) here.
| (if there is any), it is available as [`worker.threadId`][]. | ||
| This value is unique for each [`Worker`][] instance inside a single process. | ||
|
|
||
| ## `worker.threadName` |
There was a problem hiding this comment.
Just a nit since I see we don't do this with the other properties here so feel free to ignore, but it would be ideal if the docs were clear that this is a read-only property. (same goes for the other read-only properties here)
| if (this[kHandle] === null) return null; | ||
|
|
||
| return this[kHandle].threadName; |
There was a problem hiding this comment.
I believe you could simplify this a bit as...
| if (this[kHandle] === null) return null; | |
| return this[kHandle].threadName; | |
| return this[kHandle]?.threadName || null; |
There was a problem hiding this comment.
I will optimize it in another pr.Thanks.
commented
Aug 4, 2025
commented
Aug 4, 2025
commented
Aug 5, 2025
|
Landed in 3090def |
In some scenarios,
nameis very useful(such as in the APM SDK) and easier to understand.make -j4 test(UNIX), orvcbuild test(Windows) passes