Domanda

I use gevent-socketio on server and socket.io.js on client. After connection is established, client receives data that should be rendered. Rendering can take much time (up to 10 - 15 sec.) When it's done, connection aborted. I will tune performance, but it depends on data that will be rendered, so I will not decrease it dramatically. How to solve issue with braking connection after long JS process?

È stato utile?

Soluzione

I solved this issue, dividing rendering process to small peaces and executing them sequentially. For example, if I need to render 100 object, instead of rendering them in the loop, I just iterate and store functions to render each table to array. Then I call following method, placing array with actions to execute as argument:

databasy.ui.utils.executeSequentially = function (functions) {
    if (functions.length == 0) {
        return;
    }
    setTimeout(function() {
        functions[0]();
        functions.splice(0, 1);
        databasy.ui.utils.executeSequentially(functions);
    }, 0);
};

As you can see, first function is executed in setTimeout with argument 0. After it finishes, next function is scheduled. It allows touch other callbacks in the loop (including those one that needed for socket.io execution).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top