Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/cpu-prof-e2e/mocks/create-many-preoces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { spawn as _spawn } from 'node:child_process';
import { Worker, threadId } from 'node:worker_threads';

const spawn = (...args) => _spawn(...args);

console.log('Main PID:', process.pid, 'TID:', threadId);

const childScript =
"const { threadId: t } = require('worker_threads'); console.log('spawn PID:', process.pid, 'TID:', t);";
const children = [
spawn(process.execPath, ['-e', childScript], { stdio: 'inherit' }),
spawn(process.execPath, ['-e', childScript], { stdio: 'inherit' }),
];

const workerScript =
"const { threadId: t } = require('worker_threads'); console.log('Worker PID:', process.pid, 'TID:', t);";
const workers = [
new Worker(workerScript, { eval: true }),
new Worker(workerScript, { eval: true }),
];

let exited = 0;
function checkDone() {
exited++;
if (exited === children.length + workers.length) {
process.exit(0);
}
}

[...children, ...workers].forEach((child) => {
child.on('exit', checkDone);
});
Loading
Loading