MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / spawnAsync

Function spawnAsync

src/util.ts:517–554  ·  view source on GitHub ↗
(command: string, args?: ReadonlyArray<string>, options?: cp.CommonOptions, onDisposed?: () => unknown)

Source from the content-addressed store, hash-verified

515}
516
517export async function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: cp.CommonOptions, onDisposed?: () => unknown): Promise<cp.SpawnSyncReturns<string>> {
518 return new Promise((resolve) => {
519
520 const result: cp.SpawnSyncReturns<string> = {
521 error: undefined,
522 pid: -1,
523 output: [],
524 stdout: '',
525 stderr: '',
526 status: null,
527 signal: null
528 };
529
530 try {
531 const childProcess = spawn(command, args, options, onDisposed);
532 if (childProcess.pid !== undefined) {
533 result.pid = childProcess.pid;
534 }
535 childProcess.stdout?.on('data', (chunk: Buffer) => {
536 result.stdout += chunk.toString();
537 });
538 childProcess.stderr?.on('data', (chunk: Buffer) => {
539 result.stderr += chunk.toString();
540 });
541 childProcess.on('error', (err: Error) => {
542 result.error = err;
543 });
544 childProcess.on('exit', (code, signal) => {
545 result.status = code;
546 result.signal = signal;
547 resolve(result);
548 });
549 } catch (e) {
550 result.error = (e instanceof Error) ? e : undefined;
551 resolve(result);
552 }
553 });
554}
555
556/**
557 * Check if an R package is available or not

Callers 4

getTemplateItemsFunction · 0.90
getAliasesFromRMethod · 0.90
getHelpForTopicMethod · 0.90
executeRCommandFunction · 0.85

Calls 1

spawnFunction · 0.85

Tested by

no test coverage detected