MCPcopy Index your code
hub / github.com/callstack/agent-device / attachChildToStream

Function attachChildToStream

src/daemon/app-log-stream.ts:67–95  ·  view source on GitHub ↗
(
  child: StreamableChildProcess,
  stream: fs.WriteStream,
  options: {
    endStreamOnClose: boolean;
    writer: LineWriter;
  },
)

Source from the content-addressed store, hash-verified

65};
66
67export function attachChildToStream(
68 child: StreamableChildProcess,
69 stream: fs.WriteStream,
70 options: {
71 endStreamOnClose: boolean;
72 writer: LineWriter;
73 },
74): Promise<ExecResult> {
75 const stdout = child.stdout;
76 const stderr = child.stderr;
77 if (!stdout || !stderr) {
78 return Promise.resolve({ stdout: '', stderr: 'missing stdio pipes', exitCode: 1 });
79 }
80 stdout.setEncoding('utf8');
81 stderr.setEncoding('utf8');
82 stdout.on('data', options.writer.onChunk);
83 stderr.on('data', options.writer.onChunk);
84 stream.on('error', () => {
85 if (!child.killed) child.kill('SIGKILL');
86 });
87 child.on('error', () => stream.destroy());
88 return new Promise<ExecResult>((resolve) => {
89 child.on('close', (code) => {
90 options.writer.flush();
91 if (options.endStreamOnClose) stream.end();
92 resolve({ stdout: '', stderr: '', exitCode: code ?? 1 });
93 });
94 });
95}

Callers 2

startAndroidAppLogFunction · 0.90
startAppleAppLogStreamFunction · 0.90

Calls 2

resolveFunction · 0.70
killMethod · 0.45

Tested by

no test coverage detected