MCPcopy Create free account
hub / github.com/babel/babel / #runNextTask

Method #runNextTask

scripts/parallel-tsc/tsc.ts:122–168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

120 }
121
122 #runNextTask() {
123 if (this.#pending.length === 0) return;
124
125 const tasks = [this.#pending[0]];
126 let weight = this.#getWeight(tasks[0]);
127 const toRemove = new Set([0]);
128 for (let i = 1; i < this.#pending.length && weight < this.#maxWeight; i++) {
129 const task = this.#pending[i];
130 const taskWeight = this.#getWeight(task);
131 if (weight + taskWeight <= this.#maxWeight) {
132 weight += taskWeight;
133 tasks.push(task);
134 toRemove.add(i);
135 }
136 }
137 this.#pending = this.#pending.filter((_, i) => !toRemove.has(i));
138
139 const taskProcess = cp.fork(this.#filename, ["-b", ...tasks, "--pretty"], {
140 stdio: this.#showOutput(tasks) ? "inherit" : "ignore",
141 });
142
143 // eslint-disable-next-line @typescript-eslint/no-misused-promises
144 taskProcess.once("exit", async code => {
145 const startTime = this.#running.get(taskProcess)!;
146 const duration = performance.now() - startTime;
147 await this.#onTaskDone(tasks, code!, duration);
148 this.#running.delete(taskProcess);
149
150 // Spin the event loop so that #run can pick up the next task
151 await setTimeout(0);
152
153 this.#runTasks();
154
155 if (this.#running.size === 0 && this.#pending.length === 0) {
156 this.#emptyListeners.forEach(f => f());
157 }
158 });
159
160 taskProcess.once("error", err => {
161 console.error("Error in task process:", err);
162 this.#onTaskError(tasks);
163 this.#running.delete(taskProcess);
164 });
165
166 this.#onTaskStart(tasks, weight);
167 this.#running.set(taskProcess, performance.now());
168 }
169
170 #runTasks() {
171 while (this.#running.size < this.#concurrency && this.#pending.length > 0) {

Callers 1

#runTasksMethod · 0.95

Calls 8

#runTasksMethod · 0.95
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.65
fFunction · 0.50
pushMethod · 0.45
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected