title: Removing user object on socket disconnect causes error in main loop
body: <p>I have a game that has a main loop that goes something like:</p>
  
  <pre><code>for (var i = 0; i &lt; users.length; ++i) {
      users[i].value--;
      if (users[i].value) {
  
      }
  }
  </code></pre>
  
  <p>And the users is connected via a socket:</p>
  
  <pre><code>io.on('connect', function(socket) {
      var tmpUser = {};
      users.push(tmpUser);
      socket.on('disconnect', function() {
          users.splice(users.indexOf(tmpUser), 1)
      });
  })
  </code></pre>
  
  <p>Sometimes when a user disconnects it causes an error saying:</p>
  
  <pre><code>Cannot read property .value of undefined
  </code></pre>
  
  <p>I think this maybe be because the disconnect is asynchronous. How can I fix this?</p>