Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added callback to Socket.close to mimic Socket.listen. #78

Merged
merged 1 commit into from

2 participants

@james-huston

This callback is passed in to the server.close method to be called when the server closes down successfully. Mimics the functionality in Socket.listen -> server.listen.

@james-huston james-huston Added ability to pass a callback in to the Socket.close method.
This callback is passed in to the server.close method to be called when
the server closes down successfully. Mimics the functionality in
Socket.listen -> server.listen.
66379ee
@tj tj merged commit f6fe024 into tj:master
@tj
Owner
tj commented

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 28, 2012
  1. @james-huston

    Added ability to pass a callback in to the Socket.close method.

    james-huston authored
    This callback is passed in to the server.close method to be called when
    the server closes down successfully. Mimics the functionality in
    Socket.listen -> server.listen.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 2 deletions.
  1. +2 −2 lib/sockets/sock.js
  2. +20 −0 test/test.socket.close.js
View
4 lib/sockets/sock.js
@@ -149,14 +149,14 @@ Socket.prototype.closeSockets = function(){
* @api public
*/
-Socket.prototype.close = function(){
+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();
+ this.server.close(fn);
}
};
View
20 test/test.socket.close.js
@@ -0,0 +1,20 @@
+
+var axon = require('..')
+ , assert = require('better-assert');
+
+var pull = axon.socket('pull');
+
+var closed = false;
+var callbackClose = function() {
+ closed = true;
+}
+
+pull.bind(4444, function() {
+ pull.close(callbackClose);
+});
+
+pull.on('close', function() {
+ setTimeout(function() {
+ assert(closed === true);
+ }, 100);
+});
Something went wrong with that request. Please try again.