@ywfe/cli
Version:
遥望前端开发命令行工具
35 lines (34 loc) • 1.84 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const worker_pool_1 = __importDefault(require("./worker-pool"));
const os = require("os");
const threadRunner = (allPageName) => {
const length = allPageName.length;
const numThreads = os.cpus().length - 2;
console.log('正在使用的线程数:', numThreads);
const pool = new worker_pool_1.default(numThreads);
let finished = 0;
return Promise.all(allPageName.map((param) => __awaiter(void 0, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
pool.runTask(param, (err, res) => {
if (++finished === length || !(res === null || res === void 0 ? void 0 : res.success)) {
pool.close();
}
(res === null || res === void 0 ? void 0 : res.success) ? resolve(res) : reject(err || (res === null || res === void 0 ? void 0 : res.message));
});
});
})));
};
exports.default = threadRunner;