Skip to content

Commit

Permalink
fix Socket#close() callback support
Browse files Browse the repository at this point in the history
node waits for all sockets to die instead of invoking the callback
when the listening socket is closed... seems incorrect to me but
it is what it is
  • Loading branch information
tj committed Apr 13, 2013
1 parent 3dd130f commit b3ea987
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/sockets/sock.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,29 @@ Socket.prototype.closeSockets = function(){
* Delegates to the server or clients
* based on the socket `type`.
*
* @param {Function} [fn]
* @api public
*/

Socket.prototype.close = function(fn){
debug('closing');
this.closing = true;
this.closeSockets();
if (this.server) {
debug('closing server');
this.server.on('close', this.emit.bind(this, 'close'));
this.server.close(fn);
}
if (this.server) this.closeServer(fn);
};

/**
* Close the server.
*
* @param {Function} [fn]
* @api public
*/

Socket.prototype.closeServer = function(fn){
debug('closing server');
this.server.on('close', this.emit.bind(this, 'close'));
this.server.close();
fn && fn();
};

/**
Expand Down

0 comments on commit b3ea987

Please sign in to comment.