MCPcopy Create free account
hub / github.com/Keyang/node-csvtojson / initWorker

Method initWorker

src/ProcessFork.ts:56–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54 return clone;
55 }
56 private initWorker() {
57 this.childProcess.on("exit",()=>{
58 this.flushResult();
59 })
60 this.childProcess.send({
61 cmd: "init",
62 params: this.prepareParam(this.converter.parseParam)
63 } as InitMessage);
64 this.childProcess.on("message", (msg: Message) => {
65 if (msg.cmd === "inited") {
66 this.inited = true;
67 } else if (msg.cmd === "eol") {
68 if (this.converter.listeners("eol").length > 0){
69 this.converter.emit("eol",(msg as StringMessage).value);
70 }
71 }else if (msg.cmd === "header") {
72 if (this.converter.listeners("header").length > 0){
73 this.converter.emit("header",(msg as StringMessage).value);
74 }
75 }else if (msg.cmd === "done"){
76
77 // this.flushResult();
78 }
79
80 });
81 this.childProcess.stdout?.on("data", (data) => {
82 // console.log("stdout", data.toString());
83 const res = data.toString();
84 // console.log(res);
85 this.appendBuf(res);
86
87 });
88 this.childProcess.stderr?.on("data", (data) => {
89 // console.log("stderr", data.toString());
90 this.converter.emit("error", CSVError.fromJSON(JSON.parse(data.toString())));
91 });
92
93 }
94 private flushResult() {
95 // console.log("flush result", this.resultBuf.length);
96 if (this.next) {

Callers 4

constructorMethod · 0.95
ProcessorForkFunction · 0.80
ConverterFunction · 0.80
Converter.jsFile · 0.80

Calls 5

flushResultMethod · 0.95
prepareParamMethod · 0.95
appendBufMethod · 0.95
fromJSONMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected