0

In the following code after the sockets.find() statement the console.log("AFTER") statement is not executed

  io.sockets.on('connection', function (socket) {
    var this_socket = socket;
    socket.username = null;
    socket.gameSessionName = null;
    socket.update_usernames = false;
    sockets.push(socket);  // sockets is AN ARRAY

    socket.on('loaded', function (data) {
        var previous_socket;
        socket.username = data.username;
        socket.status = 'BROWSE_PLAYERS'; // WAIT_FOR_ACCEPT, PLAYING
        console.log("BEFORE");    

        previous_socket = sockets.find (function(s) {           
            return false;
        });

        console.log("AFTER"); // THIS IS STATEMENT IS NOT EXECUTED
        ....

If the socket.find() code is commented as shown below then the console.log("AFTER") statement is printed.

        // previous_socket = sockets.find (function(s) {            
        //  return false;
        // });

It looks like the sockets.find(...) statement has side effects. How to solve this issue.

Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135

0 Answers0