source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/utils/action-executor.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __importDefault = (this && this.__importDefault) || function (mod) {
10 return (mod && mod.__esModule) ? mod : { "default": mod };
11};
12Object.defineProperty(exports, "__esModule", { value: true });
13exports.BundleActionExecutor = void 0;
14const piscina_1 = __importDefault(require("piscina"));
15const action_cache_1 = require("./action-cache");
16const environment_options_1 = require("./environment-options");
17const workerFile = require.resolve('./process-bundle');
18class BundleActionExecutor {
19 constructor(workerOptions, integrityAlgorithm) {
20 this.workerOptions = workerOptions;
21 if (workerOptions.cachePath) {
22 this.cache = new action_cache_1.BundleActionCache(workerOptions.cachePath, integrityAlgorithm);
23 }
24 }
25 ensureWorkerPool() {
26 if (this.workerPool) {
27 return this.workerPool;
28 }
29 this.workerPool = new piscina_1.default({
30 filename: workerFile,
31 name: 'process',
32 workerData: this.workerOptions,
33 maxThreads: environment_options_1.maxWorkers,
34 });
35 return this.workerPool;
36 }
37 async process(action) {
38 if (this.cache) {
39 const cacheKeys = this.cache.generateCacheKeys(action);
40 action.cacheKeys = cacheKeys;
41 // Try to get cached data, if it fails fallback to processing
42 try {
43 const cachedResult = await this.cache.getCachedBundleResult(action);
44 if (cachedResult) {
45 return cachedResult;
46 }
47 }
48 catch { }
49 }
50 return this.ensureWorkerPool().run(action, { name: 'process' });
51 }
52 processAll(actions) {
53 return BundleActionExecutor.executeAll(actions, (action) => this.process(action));
54 }
55 async inline(action) {
56 return this.ensureWorkerPool().run(action, { name: 'inlineLocales' });
57 }
58 inlineAll(actions) {
59 return BundleActionExecutor.executeAll(actions, (action) => this.inline(action));
60 }
61 static async *executeAll(actions, executor) {
62 const executions = new Map();
63 for (const action of actions) {
64 const execution = executor(action);
65 executions.set(execution, execution.then((result) => {
66 executions.delete(execution);
67 return result;
68 }));
69 }
70 while (executions.size > 0) {
71 yield Promise.race(executions.values());
72 }
73 }
74 stop() {
75 var _a;
76 void ((_a = this.workerPool) === null || _a === void 0 ? void 0 : _a.destroy());
77 }
78}
79exports.BundleActionExecutor = BundleActionExecutor;
Note: See TracBrowser for help on using the repository browser.