worker: add name for worker

PR-URL: https://github.com/nodejs/node/pull/59213
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
theanarkh 2025-08-05 21:45:41 +08:00 committed by GitHub
parent a4ce69e05f
commit 3090def635
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 118 additions and 5 deletions

View file

@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker, threadName, workerData } = require('worker_threads');
const name = 'test-worker-thread-name';
if (workerData?.isWorker) {
assert.strictEqual(threadName, name);
process.exit(0);
} else {
const w = new Worker(__filename, { name, workerData: { isWorker: true } });
assert.strictEqual(w.threadName, name);
w.on('exit', common.mustCall(() => {
assert.strictEqual(w.threadName, null);
}));
}