V
V
viskeg2016-05-30 09:16:19
JavaScript
viskeg, 2016-05-30 09:16:19

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} ... ]

Those. The solution to the problem through limit \ offset does not work for me. And what is the problem:
the code hangs on the client side (the code is exemplary everywhere, but reflects the essence):
socket.on('update_recv', function(data) { 
  console.log(data);
});

on the server is this:
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); // нужна задержка, пока грубая
      }
   });
});

How can I sequentially, with time intervals, pass a bunch of lines to the front? Transferring in one "package", followed by processing there, is considered not very reasonable, plus it is not transmitted anyway.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#algooptimize #bottize, 2016-05-30
@user004

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 question

Ask a Question

731 491 924 answers to any question