@definitelytyped/utils
Advanced tools
Comparing version 0.0.179 to 0.0.180
# @definitelytyped/utils | ||
## 0.0.180 | ||
### Patch Changes | ||
- d01cacd5: Make AllPackages lazy and asynchronous | ||
## 0.0.179 | ||
@@ -4,0 +10,0 @@ |
@@ -11,10 +11,2 @@ /// <reference types="node" /> | ||
export declare function execAndThrowErrors(cmd: string, cwd?: string): Promise<string>; | ||
export interface RunWithChildProcessesOptions<In> { | ||
readonly inputs: readonly In[]; | ||
readonly commandLineArgs: string[]; | ||
readonly workerFile: string; | ||
readonly nProcesses: number; | ||
handleOutput(output: unknown): void; | ||
} | ||
export declare function runWithChildProcesses<In>({ inputs, commandLineArgs, workerFile, nProcesses, handleOutput, }: RunWithChildProcessesOptions<In>): Promise<void>; | ||
export declare const enum CrashRecoveryState { | ||
@@ -21,0 +13,0 @@ Normal = 0, |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.runWithListeningChildProcesses = exports.runWithChildProcesses = exports.execAndThrowErrors = exports.exec = void 0; | ||
exports.runWithListeningChildProcesses = exports.execAndThrowErrors = exports.exec = void 0; | ||
const assert_1 = __importDefault(require("assert")); | ||
@@ -34,55 +34,2 @@ const child_process_1 = require("child_process"); | ||
exports.execAndThrowErrors = execAndThrowErrors; | ||
function runWithChildProcesses({ inputs, commandLineArgs, workerFile, nProcesses, handleOutput, }) { | ||
return new Promise(async (resolve, reject) => { | ||
const nPerProcess = Math.floor(inputs.length / nProcesses); | ||
let processesLeft = nProcesses; | ||
let rejected = false; | ||
const allChildren = []; | ||
for (let i = 0; i < nProcesses; i++) { | ||
const lo = nPerProcess * i; | ||
const hi = i === nProcesses - 1 ? inputs.length : lo + nPerProcess; | ||
let outputsLeft = hi - lo; // Expect one output per input | ||
if (outputsLeft === 0) { | ||
// No work for this process to do, so don't launch it | ||
processesLeft--; | ||
continue; | ||
} | ||
const child = (0, child_process_1.fork)(workerFile, commandLineArgs, { | ||
execArgv: await getChildProcessExecArgv(i), | ||
}); | ||
allChildren.push(child); | ||
child.send(inputs.slice(lo, hi)); | ||
child.on("message", (outputMessage) => { | ||
handleOutput(outputMessage); | ||
(0, assert_1.default)(outputsLeft > 0); | ||
outputsLeft--; | ||
if (outputsLeft === 0) { | ||
(0, assert_1.default)(processesLeft > 0); | ||
processesLeft--; | ||
if (processesLeft === 0) { | ||
resolve(); | ||
} | ||
child.kill(); | ||
} | ||
}); | ||
child.on("disconnect", () => { | ||
if (outputsLeft !== 0) { | ||
fail(new Error(`disconnect with ${outputsLeft} outputs left`)); | ||
} | ||
}); | ||
child.on("close", () => { | ||
(0, assert_1.default)(rejected || outputsLeft === 0); | ||
}); | ||
child.on("error", fail); | ||
} | ||
function fail(e) { | ||
rejected = true; | ||
for (const child of allChildren) { | ||
child.kill(); | ||
} | ||
reject(e); | ||
} | ||
}); | ||
} | ||
exports.runWithChildProcesses = runWithChildProcesses; | ||
function runWithListeningChildProcesses({ inputs, commandLineArgs, workerFile, nProcesses, cwd, handleOutput, crashRecovery, crashRecoveryMaxOldSpaceSize = DEFAULT_CRASH_RECOVERY_MAX_OLD_SPACE_SIZE, childRestartTaskInterval = DEFAULT_CHILD_RESTART_TASK_INTERVAL, handleStart, handleCrash, softTimeoutMs = Infinity, }) { | ||
@@ -89,0 +36,0 @@ return new Promise(async (resolve, reject) => { |
{ | ||
"name": "@definitelytyped/utils", | ||
"version": "0.0.179", | ||
"version": "0.0.180", | ||
"description": "Shared utilities for DefinitelyTyped tools", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/utils#readme", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126635
1892