-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
inspector: report all workers #28872
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| common.skipIfInspectorDisabled(); | ||
|
|
||
| const { Session } = require('inspector'); | ||
| const { Worker, isMainThread, parentPort } = require('worker_threads'); | ||
|
|
||
| const MAX_DEPTH = 3; | ||
|
|
||
| let rootWorker = null; | ||
|
|
||
| function runTest() { | ||
|
||
| let reportedWorkersCount = 0; | ||
| const session = new Session(); | ||
| session.connect(); | ||
| session.on('NodeWorker.attachedToWorker', ({ params: { workerInfo } }) => { | ||
|
||
| console.log(`Worker ${workerInfo.title} was reported`); | ||
| if (++reportedWorkersCount === MAX_DEPTH) { | ||
| rootWorker.postMessage({ done: true }); | ||
| } | ||
| }); | ||
| session.post('NodeWorker.enable', { waitForDebuggerOnStart: false }); | ||
| } | ||
|
|
||
| function processMessage({ child }) { | ||
| console.log(`Worker ${child} is running`); | ||
| if (child === MAX_DEPTH) { | ||
| runTest(); | ||
| } | ||
| } | ||
|
|
||
| function workerCallback(message) { | ||
| parentPort.postMessage(message); | ||
| } | ||
|
|
||
| function startWorker(depth, messageCallback) { | ||
| const worker = new Worker(__filename); | ||
| worker.on('message', messageCallback); | ||
| worker.postMessage({ depth }); | ||
| return worker; | ||
| } | ||
|
|
||
| function runMainThread() { | ||
| rootWorker = startWorker(1, processMessage); | ||
| } | ||
|
|
||
| function runWorkerThread() { | ||
| let worker = null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename this to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| parentPort.on('message', ({ child, depth, done }) => { | ||
| if (done) { | ||
| if (worker) { | ||
| worker.postMessage({ done: true }); | ||
| } | ||
| parentPort.close(); | ||
| } else if (depth) { | ||
| parentPort.postMessage({ child: depth }); | ||
| if (depth < MAX_DEPTH) { | ||
| worker = startWorker(depth + 1, workerCallback); | ||
| } | ||
| } else if (child) { | ||
| parentPort.postMessage({ child }); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| if (isMainThread) { | ||
| runMainThread(); | ||
| } else { | ||
| runWorkerThread(); | ||
| } | ||
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.
Btw, if you need member fields to be destroyed in a specific order, it might make the sense to re-order the fields so that that happens automatically?
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 would like to have this specified explicitly so I don't cause crashes by moving fields in the header file. Had that happen before :)