-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
worker: add name for worker #59213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! ![]()
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 ! |
07eb563 to
d1f417c
Compare
d1f417c to
6f7e498
Compare
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workerData?.isWorker is designed to support the creation of worker within worker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no reason for process.exit(0) here.
| @@ -721,6 +721,17 @@ An integer identifier for the current thread. On the corresponding worker object | |||
| (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will optimize it in another pr.Thanks.
|
Landed in 3090def |
PR-URL: nodejs#59213 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #59213 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#59213 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#59213 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #59213 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

In some scenarios,
nameis very useful(such as in the APM SDK) and easier to understand.make -j4 test(UNIX), orvcbuild test(Windows) passes