node/test/fixtures/worker-name.js
Debadree Chatterjee 2d9bf91fe1
worker: add support for worker name in inspector and trace_events
Fixes: https://github.com/nodejs/node/issues/41589
PR-URL: https://github.com/nodejs/node/pull/46832
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2023-03-06 16:34:09 +00:00

18 lines
484 B
JavaScript

const { Session } = require('inspector');
const { parentPort } = require('worker_threads');
const session = new Session();
parentPort.once('message', () => {}); // Prevent the worker from exiting.
session.connectToMainThread();
session.on(
'NodeWorker.attachedToWorker',
({ params: { workerInfo } }) => {
// send the worker title to the main thread
parentPort.postMessage(workerInfo.title);
}
);
session.post('NodeWorker.enable', { waitForDebuggerOnStart: false });