MCPcopy
hub / github.com/webpack/tapable / callTapsParallel

Method callTapsParallel

lib/HookCodeFactory.js:389–455  ·  view source on GitHub ↗
({
		onError,
		onResult,
		onDone,
		rethrowIfPossible,
		onTap = (i, run) => run()
	})

Source from the content-addressed store, hash-verified

387 }
388
389 callTapsParallel({
390 onError,
391 onResult,
392 onDone,
393 rethrowIfPossible,
394 onTap = (i, run) => run()
395 }) {
396 const { taps } = this.options;
397 const tapsLength = taps.length;
398 if (tapsLength <= 1) {
399 return this.callTapsSeries({
400 onError,
401 onResult,
402 onDone,
403 rethrowIfPossible
404 });
405 }
406 // done and doneBreak don't depend on the loop variable - hoist them
407 // so they're allocated once per compile instead of once per tap.
408 const done = () => {
409 if (onDone) return "if(--_counter === 0) _done();\n";
410 return "--_counter;";
411 };
412 const doneBreak = (skipDone) => {
413 if (skipDone || !onDone) return "_counter = 0;\n";
414 return "_counter = 0;\n_done();\n";
415 };
416 let code = "";
417 code += "do {\n";
418 code += `var _counter = ${tapsLength};\n`;
419 if (onDone) {
420 code += "var _done = (function() {\n";
421 code += onDone();
422 code += "});\n";
423 }
424 for (let i = 0; i < tapsLength; i++) {
425 code += "if(_counter <= 0) break;\n";
426 code += onTap(
427 i,
428 () =>
429 this.callTap(i, {
430 onError: (error) => {
431 let code = "";
432 code += "if(_counter > 0) {\n";
433 code += onError(i, error, done, doneBreak);
434 code += "}\n";
435 return code;
436 },
437 onResult:
438 onResult &&
439 ((result) => {
440 let code = "";
441 code += "if(_counter > 0) {\n";
442 code += onResult(i, result, done, doneBreak);
443 code += "}\n";
444 return code;
445 }),
446 onDone: !onResult && (() => done()),

Callers 3

contentMethod · 0.80
contentMethod · 0.80

Calls 3

callTapsSeriesMethod · 0.95
callTapMethod · 0.95
doneFunction · 0.50

Tested by

no test coverage detected