MCPcopy
hub / github.com/plasma-umass/browsix / main

Function main

src/bin/pipeline-example.ts:10–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import { pipe2 } from 'node-pipe2';
9
10function main(): void {
11 'use strict';
12
13 let pathToScript = process.argv[1];
14 let args = process.argv.slice(2);
15 let waiting = 2;
16 let exit = 0;
17
18 function childFinished(err: any, code: number = 0): void {
19 if (err && !code)
20 code = -1;
21 waiting--;
22 if (!waiting)
23 process.exit(code);
24 }
25
26 pipe2((perr: any, rfd: number, wfd: number) => {
27 if (perr)
28 throw new Error('pipe2 failed: ' + perr);
29
30 let echo = child_process.spawn('/usr/bin/echo', ['hello world'], { stdio: [0, wfd, 2] });
31 echo.on('error', (err: any) => {
32 process.stderr.write('error: ' + err, () => {
33 exit = 1;
34 childFinished(err);
35 });
36 });
37 echo.on('exit', (code: number) => {
38 childFinished(null, code);
39 });
40
41 // XXX: we don't need the wfd at this point, and
42 // keeping it open seems to prevent cat from getting
43 // an EOF on the pipe?
44 fs.close(wfd, () => {
45 let cat = child_process.spawn('/usr/bin/cat', [], { stdio: [rfd, 1, 2] });
46 cat.on('error', (err: any) => {
47 process.stderr.write('error: ' + err, () => {
48 childFinished(err);
49 });
50 });
51 cat.on('exit', (code: number) => {
52 childFinished(null, code);
53 });
54 fs.close(rfd);
55 });
56
57 });
58}
59
60main();

Callers 1

Calls 6

childFinishedFunction · 0.85
sliceMethod · 0.65
onMethod · 0.65
writeMethod · 0.65
closeMethod · 0.65
spawnMethod · 0.45

Tested by

no test coverage detected