Skip to content

Commit 837604b

Browse files
authored
Fix situation with JSON.parse crashing
1. Sometimes we get only part of data, so we should wait for other parts. 2. I hope, that we can get only 1 tickData at the time
1 parent 43c7b8c commit 837604b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

remote-process-client.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ module.exports.connect = function connect(host, port, onConnect) {
3939
process.exit();
4040
});
4141

42+
let tickData = '';
4243
function dataHandler(data) {
4344
busy = true;
4445
if (data) {
45-
strBuffer = strBuffer.concat(data.toString().split("\n").filter((item) => { return item.length }));
46+
// sometimes we get tick data by parts
47+
tickData = tickData + data.toString();
48+
// tickData is complete when we get '\n'
49+
if (tickData[tickData.length -1] === '\n') {
50+
strBuffer.push(tickData);
51+
tickData = '';
52+
}
4653
}
4754
while (request.length && strBuffer.length) {
4855
let cb = request.shift();
@@ -102,4 +109,4 @@ module.exports.connect = function connect(host, port, onConnect) {
102109
writeline(token);
103110
cb();
104111
}
105-
}
112+
}

0 commit comments

Comments
 (0)