本文整理汇总了TypeScript中child_process.fork函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fork函数的具体用法?TypeScript fork怎么用?TypeScript fork使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fork函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: _spawnSharedProcess
function _spawnSharedProcess(options: ISharedProcessOptions): cp.ChildProcess {
const execArgv = [];
const env = assign({}, process.env, {
AMD_ENTRYPOINT: 'vs/code/node/sharedProcessMain'
});
if (options.allowOutput) {
env['VSCODE_ALLOW_IO'] = 'true';
}
if (options.debugPort) {
execArgv.push(`--debug=${ options.debugPort }`);
}
const result = cp.fork(boostrapPath, ['--type=SharedProcess'], { env, execArgv });
// handshake
result.once('message', () => result.send('hey'));
return result;
}
开发者ID:1Hgm,项目名称:vscode,代码行数:21,代码来源:sharedProcess.ts
示例2: Promise
return new Promise((resolve, reject) => {
const buildProcess = fork(binary, [command, workspaceTarget, ...flags], {
cwd: projectDir,
stdio: 'inherit',
});
process.on('SIGINT', (signal) => {
if (!buildProcess.killed) {
buildProcess.kill();
reject(new Error(`Bazel process received ${signal}.`));
}
});
buildProcess.once('close', (code: number) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`${binary} failed with code ${code}.`));
}
});
});
开发者ID:alxhub,项目名称:angular,代码行数:21,代码来源:bazel.ts
示例3: spawnLintWorker
function spawnLintWorker(files: {path: string}[], callback: (failures: number) => void) {
const child = cp.fork("./scripts/parallel-lint");
let failures = 0;
child.on("message", function(data) {
switch (data.kind) {
case "result":
if (data.failures > 0) {
failures += data.failures;
console.log(data.output);
}
sendNextFile(files, child, callback, failures);
break;
case "error":
console.error(data.error);
failures++;
sendNextFile(files, child, callback, failures);
break;
}
});
sendNextFile(files, child, callback, failures);
}
开发者ID:mihailik,项目名称:TypeScript,代码行数:21,代码来源:Gulpfile.ts
示例4: spawnSharedProcess
export function spawnSharedProcess(): cp.ChildProcess {
const result = cp.fork(boostrapPath, ['--type=SharedProcess'], {
env: assign(assign({}, process.env), {
AMD_ENTRYPOINT: 'vs/workbench/parts/sharedProcess/node/sharedProcessMain'
})
});
// handshake
result.once('message', () => {
result.send({
configuration: {
env: getEnvironment()
},
contextServiceOptions: {
globalSettings: SettingsManager.globalSettings
}
});
});
return result;
}
开发者ID:gaoxiaojun,项目名称:vscode,代码行数:21,代码来源:sharedProcess.ts
示例5: runCommand
export async function runCommand(
path: string, args: string[], options: Options): Promise<string> {
let commandError: Error|undefined = undefined;
options.silent = true;
const forkedProcess = childProcess.fork(path, args, options);
const outputPromise =
pipesToString(forkedProcess.stdout!, forkedProcess.stderr!);
// listen for errors as they may prevent the exit event from firing
forkedProcess.on('error', (error) => {
commandError = error;
});
const exitCode = await new Promise<number>((resolve) => {
forkedProcess.on('exit', resolve);
});
if (exitCode !== 0) {
commandError = new Error(
`Error running ${path} with args ${args}. ` +
`Got exit code: ${exitCode}`);
}
if (!commandError) {
return outputPromise;
}
// If the command was successful there's no need to print anything to
// the console, but if it failed then its output is probably helpful.
// Print out the output, then reject the final result with the original
// error.
const out = await outputPromise;
if (options.failureExpected) {
// Throw the output string as our error if failure is expected.
throw out;
}
console.log(
`Output of failed command 'node ${path} ${args.join(' ')}' ` +
`in directory ${options.cwd}`);
console.log(out);
throw commandError;
}
开发者ID:Polymer,项目名称:tools,代码行数:39,代码来源:run-command.ts
示例6: fork
let startProcess = () => {
lintProcess = fork(`${__dirname}/linter-process`, [], {
execArgv: process.execArgv.filter(arg => !arg.includes('inspect'))
});
lintProcess.on('close', (code: number) => {
if (code !== 0 && code !== null) {
logger.log('linter', `linting process exited with code ${code}`);
}
});
lintProcess.on('message', (response: LinterResponse) => {
if (response.violation) {
let { fileName, line, column, message, hasFix } = response.violation;
errors++;
if (hasFix) {
fixable++;
}
logger.log('linter', `${absolutePath(fileName)}:${line}:${column} ${message}`);
}
if (response.finished) {
running = false;
logger.log('linter', response.finished.success
? 'All files are ok'
: `${errors} Linting problems found, ${fixable} ${fix ? 'fixed' : 'fixable'}`);
bus.signal(response.finished.success ? 'lint-linted' : 'lint-errored');
bus.report({
tool: 'lint',
status: 'ready',
errors: errors,
fixable: fixable
});
if (rescheduled) {
startLint().catch(logError);
}
}
if (response.error) {
logger.error('linter', response.error.message);
}
});
};
开发者ID:AFASSoftware,项目名称:typescript-assistant,代码行数:39,代码来源:linter.ts
示例7: forkSererProcess
export default function forkSererProcess(extraArgs: string[] = []) {
const serverPath = `${settings.corePath}/server/index.js`;
const serverEnv: { [key: string]: string; } = {};
serverEnv["ELECTRON_RUN_AS_NODE"] = "1";
serverEnv["ELECTRON_NO_ATTACH_CONSOLE"] = "1";
// NOTE: It would be nice to simply copy all environment variables
// but somehow, this prevents Electron 0.35.1 from starting the server
// for (const key in nodeProcess.env) serverEnv[key] = nodeProcess.env[key];
// So instead, we'll just copy the environment variables we definitely need
for (const varName of [ "NODE_ENV", "APPDATA", "HOME", "XDG_DATA_HOME" ]) {
if (process.env[varName] != null) serverEnv[varName] = process.env[varName];
}
const serverProcess = fork(
serverPath,
[ `--data-path=${settings.userDataPath}` ].concat(extraArgs),
{ silent: true, env: serverEnv }
);
return serverProcess;
}
开发者ID:MSylvia,项目名称:superpowers-app,代码行数:23,代码来源:forkServerProcess.ts
示例8: fork
return q.Promise((resolve, reject) => {
this.checkSupportedConfig();
let args = [
'--fork', '--seleniumAddress', this.config.seleniumAddress, '--rootElement',
this.config.rootElement
];
this.bpProcess = fork(BP_PATH, args, {silent: true});
logger.info('Starting BlockingProxy with args: ' + args.toString());
this.bpProcess
.on('message',
(data) => {
this.port = data['port'];
resolve(data['port']);
})
.on('error',
(err) => {
reject(new Error('Unable to start BlockingProxy ' + err));
})
.on('exit', (code: number, signal: number) => {
reject(new Error('BP exited with ' + code));
logger.error('Exited with ' + code);
logger.error('signal ' + signal);
});
this.bpProcess.stdout.on('data', (msg: Buffer) => {
logger.debug(msg.toString().trim());
});
this.bpProcess.stderr.on('data', (msg: Buffer) => {
logger.error(msg.toString().trim());
});
process.on('exit', () => {
this.bpProcess.kill();
});
});
开发者ID:JesseChezenko-AI,项目名称:protractor,代码行数:37,代码来源:bpRunner.ts
示例9: Error
return new Promise<void>((c, e) => {
const child = cp.fork(
__filename,
[MARKER_ARGUMENT, base64encode(JSON.stringify(options))],
{
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
}
);
let stderr: Buffer[] = [];
child.stderr.on('data', (chunk) => {
stderr.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
});
child.on('exit', (code) => {
if (code === 0) {
// normal termination
console.log(`Finished downloading ${url}.`);
c();
} else {
// abnormal termination
console.error(Buffer.concat(stderr).toString());
e(new Error(`Download of ${url} failed.`));
}
});
});
开发者ID:PKRoma,项目名称:vscode,代码行数:24,代码来源:download.ts
示例10: _spawnSharedProcess
function _spawnSharedProcess(envService: IEnvironmentService, updateManager: IUpdateService, settingsManager: ISettingsService): cp.ChildProcess {
// Make sure the nls configuration travels to the shared process.
const opts = {
env: assign(assign({}, process.env), {
AMD_ENTRYPOINT: 'vs/code/node/sharedProcessMain'
})
};
const result = cp.fork(boostrapPath, ['--type=SharedProcess'], opts);
// handshake
result.once('message', () => {
result.send({
configuration: {
env: getEnvironment(envService, updateManager)
},
contextServiceOptions: {
globalSettings: settingsManager.globalSettings
}
});
});
return result;
}
开发者ID:Elflyy,项目名称:vscode,代码行数:24,代码来源:sharedProcess.ts
注:本文中的child_process.fork函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论