server/lib/client-manager.js
function shutdown(callback) {
  var closed = 0;
  var connected = clients ? clients.length : 0;

  function maybeFinished() {
    if(++closed >= connected) {
      clients = null;
      log.info('[Shutdown] All client connections safely closed.');
      return callback();
    }

    log.info('[Shutdown] Closed client %s of %s.', closed, connected);
  }

  if(!connected) {
    return maybeFinished();
  }

  var client;

  for(var i = 0; i < connected; i++) {
    client = clients[i] || null;

    if(!client) {
      maybeFinished();
    } else {
      client.once('closed', maybeFinished);

      if(client.state !== States.CLOSING && client.state !== States.CLOSED) {
        client.close();
      }
    }
  }
}
function shutdown(callback) {
  var closed = 0;
  var connected = clients ? clients.length : 0;

  function maybeFinished() {
    if(++closed >= connected) {
      clients = null;
      log.info('[Shutdown] All client connections safely closed.');
      return callback();
    }

    log.info('[Shutdown] Closed client %s of %s.', closed, connected);
  }

  if(!connected) {
    return maybeFinished();
  }

  var client;

  for(var i = 0; i < connected; i++) {
    client = clients[i] || null;

    if(!client) {
      maybeFinished();
    } else {
      client.once('closed', maybeFinished);

      if(client.state !== States.CLOSING && client.state !== States.CLOSED) {
        client.close();
      }
    }
  }
}
function shutdown ( callback ) { var closed = 0 ; var connected = clients ? clients . length : 0 ; function maybeFinished ( ) { if ( ++ closed >= connected ) { clients = null ; log . info ( '[Shutdown] All client connections safely closed.' ) ; return callback ( ) ; } log . info ( '[Shutdown] Closed client %s of %s.' , closed , connected ) ; } if ( ! connected ) { return maybeFinished ( ) ; } var client ; for ( var i = 0 ; i < connected ; i ++ ) { client = clients [ i ] || null ; if ( ! client ) { maybeFinished ( ) ; } else { client . once ( 'closed' , maybeFinished ) ; if ( client . state !== States . CLOSING && client . state !== States . CLOSED ) { client . close ( ) ; } } } }
Safe shutdown, waiting on all clients to close.
Safe shutdown waiting on all clients to close .