MCPcopy Create free account
hub / github.com/angular/dev-infra / runCommandInThread

Function runCommandInThread

ng-dev/format/run-commands-parallel.ts:86–130  ·  view source on GitHub ↗
(thread: number)

Source from the content-addressed store, hash-verified

84 // Recursively run the command on the next available file from the list using the provided
85 // thread.
86 function runCommandInThread(thread: number) {
87 const nextCommand = pendingCommands.pop();
88 // If no file was pulled from the array, return as there are no more files to run against.
89 if (nextCommand === undefined) {
90 threads[thread] = false;
91 return;
92 }
93
94 // Get the file and formatter for the next command.
95 const {file, formatter} = nextCommand;
96
97 if (lstatSync(file).isSymbolicLink()) {
98 throw new Error(`Security violation: symlink detected for file ${file}`);
99 }
100
101 const [spawnCmd, ...spawnArgs] = [...formatter.commandFor(action), '--', file];
102
103 ChildProcess.spawn(spawnCmd, spawnArgs, {
104 suppressErrorOnFailingExitCode: true,
105 mode: 'silent',
106 }).then(({stdout, stderr, status}: SpawnResult) => {
107 // Run the provided callback function.
108 const failed = formatter.callbackFor(action)(file, status, stdout, stderr);
109 if (failed) {
110 failures.push({filePath: file, message: stderr});
111 }
112 // Note in the progress bar another file being completed.
113 progressBar.increment(1);
114 // If more files exist in the list, run again to work on the next file,
115 // using the same slot.
116 if (pendingCommands.length) {
117 return runCommandInThread(thread);
118 }
119 // If not more files are available, mark the thread as unused.
120 threads[thread] = false;
121 // If all of the threads are false, as they are unused, mark the progress bar
122 // completed and resolve the promise.
123 if (threads.every((active) => !active)) {
124 progressBar.stop();
125 resolve(failures);
126 }
127 });
128 // Mark the thread as in use as the command execution has been started.
129 threads[thread] = true;
130 }
131
132 // Start the progress bar
133 progressBar.start(pendingCommands.length, 0);

Callers 1

runFormatterInParallelFunction · 0.85

Calls 2

resolveFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected