So I get my data (in JSON format) from a website's websocket. It works, but the problem is that handling this data is not as time efficient as I wish it to be (every milisecond matters). Currently my handler looks like this:
var events_channel = pusher.subscribe('changes');
const eventsQueue = [];
events_channel.bind('channel1', function(data)
{
eventsQueue.push(data);
handleNewEvent();
});
events_channel.bind('channel2', function(data)
{
eventsQueue.push(data);
handleNewEvent();
});
let processingEvent = false;
function handleNewEvent()
{
if(processingEvent){return;}
processingEvent = true;
const eventData = eventsQueue.shift();
if(!eventData){processingEvent = false; return;}
//Parse the data and do some other stuff with it
processingEvent = false;
handleNewEvent();
return;
}
I have no say over how the websocket works on the server side, so I'm wondering if there is a way to save an extra milisecond or two, or if this is basically it in regards to what I can do efficiency wise.