Browse files

Add listening callback to constructor arguments

  • Loading branch information...
1 parent 0573f96 commit 0c3de93a3f79058b10312cf6a24c1c719afbb328 @timoxley timoxley committed Sep 4, 2012
Showing with 10 additions and 13 deletions.
  1. +3 −5 lib/server.js
  2. +4 −4 lib/xmlrpc.js
  3. +3 −4 test/server_test.js
View
8 lib/server.js
@@ -20,12 +20,12 @@ var http = require('http')
* otherwise false.
* @return {Server}
*/
-function Server(options, isSecure) {
+function Server(options, isSecure, onListening) {
if (false === (this instanceof Server)) {
return new Server(options, isSecure)
}
-
+ onListening = onListening || function() {}
var that = this
// If a string URI is passed in, converts to URI fields
@@ -63,9 +63,7 @@ function Server(options, isSecure) {
: http.createServer(handleMethodCall)
process.nextTick(function() {
- this.httpServer.listen(options.port, options.host, function() {
- this.emit('listening')
- }.bind(this))
+ this.httpServer.listen(options.port, options.host, onListening)
}.bind(this))
this.close = function(callback) {
this.httpServer.once('close', callback)
View
8 lib/xmlrpc.js
@@ -38,8 +38,8 @@ xmlrpc.createSecureClient = function(options) {
* @return {Server}
* @see Server
*/
-xmlrpc.createServer = function(options) {
- return new Server(options, false)
+xmlrpc.createServer = function(options, callback) {
+ return new Server(options, false, callback)
}
/**
@@ -51,7 +51,7 @@ xmlrpc.createServer = function(options) {
* @return {Server}
* @see Server
*/
-xmlrpc.createSecureServer = function(options) {
- return new Server(options, true)
+xmlrpc.createSecureServer = function(options, callback) {
+ return new Server(options, true, callback)
}
View
7 test/server_test.js
@@ -103,12 +103,11 @@ vows.describe('Server').addBatch({
}
, 'close()': {
topic: function() {
+ console.log()
var that = this
- var server = new Server({ port: 9995, path: '/'}, false)
- server.on('listening', function() {
+ var server = new Server({ port: 9995, path: '/'}, false, function() {
server.close(function() {
- var server2 = new Server({ port: 9995, path: '/'}, false)
- server2.on('listening', that.callback)
+ var server2 = new Server({ port: 9995, path: '/'}, false, that.callback)
})
})
}

0 comments on commit 0c3de93

Please sign in to comment.