Skip to content

Commit 82835aa

Browse files
committed
Merge pull request molnarg#168 from PhilippSoehnlein/master
Allow chaining for Server.listen and Server.on
2 parents 33f912a + f1fc002 commit 82835aa

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/http.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ Server.prototype.listen = function listen(port, hostname) {
536536
this._log.info({ on: ((typeof hostname === 'string') ? (hostname + ':' + port) : port) },
537537
'Listening for incoming connections');
538538
this._server.listen.apply(this._server, arguments);
539+
540+
return this._server;
539541
};
540542

541543
Server.prototype.close = function close(callback) {
@@ -570,9 +572,9 @@ Object.defineProperty(Server.prototype, 'timeout', {
570572
// `server` to `this` since that means a listener. Instead, we forward the subscriptions.
571573
Server.prototype.on = function on(event, listener) {
572574
if ((event === 'upgrade') || (event === 'timeout')) {
573-
this._server.on(event, listener && listener.bind(this));
575+
return this._server.on(event, listener && listener.bind(this));
574576
} else {
575-
EventEmitter.prototype.on.call(this, event, listener);
577+
return EventEmitter.prototype.on.call(this, event, listener);
576578
}
577579
};
578580

0 commit comments

Comments
 (0)