Friday, 5 May 2017

Remove Listeners after emit on click - Advice

I am new to node and i have been playing while developing an app and so far so good. I am using socket.io with http server. All work as expected but.... i have a button that emit to the socket and after 10 clicks i get a warning on the logs about the event memory leak detected and to setMaxListeners. So far i saw on other questions, i must remove the listeners after emit instead of take the shortcut of increase the Max Listeners, but i have been trying without success.

My client side code looks like:

$(document).ready(function () {            
        $("#validate").click(function () {
            socket.emit('stop', "validate button");
        });
    });

On the server side:

io.sockets.on('connection', function (socket) {

    // WE RECEIVE stop
    socket.on('stop', function (msg) {
        console.log(msg);            
        clearInterval(refresh);
    });
});

How can i remove the listener after the event?

Any lights will be appreciated. Thanks in advance



via Aramil

No comments:

Post a Comment