Answer the question
In order to leave comments, you need to log in
How to pass a lot of data sequentially through Socket.io?
From the server side, an SQL query is made, resulting in a lot of data. 15k lines on average. This chunk of strings is then sorted by date, where date is the array key, and the value of each is a list of objects for that date. Those. something like:
points[row.time_update] = [ {val1: 1, val2: 123, val6:321}, {val1: 21, val2: 777, val6:2} ... ]
socket.on('update_recv', function(data) {
console.log(data);
});
socket.on('update', function(data){
knex(sql .... ).then(function(rows){
// обрабатываем строки, собираем массив points требуемого формата.
var keys = Object.keys(points); // необходимость выдавать порционно по датам
for( var k in keys )
{
// вот тут начинается неведомая мне магия. Если брякнуть после socket.emit
// то данные прилетают. т.е. 1 раз. в ином случае цикл идет, но на фронт
// ничего не приходит.
socket.emit('update_recv', {result: JSON.stringify(points[keys[k]]) })
sleep.sleep(3); // нужна задержка, пока грубая
}
});
});
Answer the question
In order to leave comments, you need to log in
It's hard to see from a mobile, but the data is drawn to economical packaging
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question