MCPcopy
hub / github.com/webpack/webpack / processIdleTasks

Method processIdleTasks

lib/cache/IdleFileCachePlugin.js:142–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140 let isIdle = false;
141 let isInitialStore = true;
142 const processIdleTasks = () => {
143 if (isIdle) {
144 const startTime = Date.now();
145 if (pendingIdleTasks.size > 0) {
146 const promises = [currentIdlePromise];
147 const maxTime = startTime + 100;
148 let maxCount = 100;
149 for (const [filename, factory] of pendingIdleTasks) {
150 pendingIdleTasks.delete(filename);
151 promises.push(factory());
152 if (maxCount-- <= 0 || Date.now() > maxTime) break;
153 }
154 currentIdlePromise = Promise.all(
155 /** @type {Promise<void>[]} */
156 (promises)
157 );
158 currentIdlePromise.then(() => {
159 timeSpendInStore += Date.now() - startTime;
160 // Allow to exit the process between
161 idleTimer = setTimeout(processIdleTasks, 0);
162 idleTimer.unref();
163 });
164 return;
165 }
166 currentIdlePromise = currentIdlePromise
167 .then(async () => {
168 await strategy.afterAllStored();
169 timeSpendInStore += Date.now() - startTime;
170 avgTimeSpendInStore =
171 Math.max(avgTimeSpendInStore, timeSpendInStore) * 0.9 +
172 timeSpendInStore * 0.1;
173 timeSpendInStore = 0;
174 timeSpendInBuild = 0;
175 })
176 .catch((err) => {
177 const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
178 logger.warn(`Background tasks during idle failed: ${err.message}`);
179 logger.debug(err.stack);
180 });
181 isInitialStore = false;
182 }
183 };
184 /** @type {ReturnType<typeof setTimeout> | undefined} */
185 let idleTimer;
186 compiler.cache.hooks.beginIdle.tap(

Callers

nothing calls this directly

Calls 6

afterAllStoredMethod · 0.80
warnMethod · 0.80
debugMethod · 0.80
deleteMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected