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

Function sort

src/bin/sort.ts:20–55  ·  view source on GitHub ↗
(inputs: NodeJS.ReadableStream[], output: NodeJS.WritableStream, code: number, lines: string[])

Source from the content-addressed store, hash-verified

18// event listeners, the first for when there is data available, and
19// secondly for when we've reached EOF.
20function sort(inputs: NodeJS.ReadableStream[], output: NodeJS.WritableStream, code: number, lines: string[]): void {
21 'use strict';
22
23 if (!inputs || !inputs.length) {
24 lines.sort();
25 output.write(lines.join('\n') + '\n', () => {
26 process.exit(code);
27 });
28 return;
29 }
30
31 let current = inputs[0];
32 inputs = inputs.slice(1);
33
34 if (!current) {
35 // use setTimeout to avoid a deep stack as well as
36 // cooperatively yield
37 setTimeout(sort, 0, inputs, output, code, lines);
38 return;
39 }
40
41 current.on('readable', function(): void {
42 let rl = readline.createInterface({
43 input: current,
44 output: null
45 });
46
47 rl.on('line', (line: string) => {
48 lines.push(line);
49 });
50 });
51
52 current.on('end', function(): void {
53 setTimeout(sort, 0, inputs, output, code, lines);
54 });
55}
56
57function main(): void {
58 'use strict';

Callers

nothing calls this directly

Calls 4

writeMethod · 0.65
exitMethod · 0.65
sliceMethod · 0.65
onMethod · 0.65

Tested by

no test coverage detected