Skip to content

Commit b76e169

Browse files
committed
add worker
1 parent 5d58841 commit b76e169

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

libs/core/worker.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var param=null;
2+
var dataToCSVLine=require("dataToCSVLine");
3+
process.on("message",function(msg){
4+
var cmd=msg[0];
5+
var data=msg.substr(1);
6+
switch (cmd){
7+
case 0:
8+
initParams(data);
9+
break;
10+
case 1:
11+
processData(data);
12+
break;
13+
default:
14+
console.error("Unknown command: ",msg);
15+
}
16+
});
17+
18+
function initParams(data){
19+
if (!param){
20+
param=JSON.parse(data);
21+
}
22+
}
23+
24+
function processData(data){
25+
if (!param){
26+
console.error("Parameter not initialised when processing data.");
27+
process.exit(1);
28+
}
29+
var sepIdx=data.indexOf("|");
30+
var startIdx=parseInt(data.substr(0,sepIdx));
31+
var csvData=data.substr(sepIdx+1);
32+
var lines=dataToCSVLine(csvData,param);
33+
process.send("0"+startIdx+"|"+lines.lines.length+"|"+lines.partial);
34+
}
35+

0 commit comments

Comments
 (0)