Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

.close() should take a callback. #2762

mikeal opened this Issue Feb 16, 2012 · 2 comments


None yet
3 participants

mikeal commented Feb 16, 2012

Realized that this is a lot of unnecessary boiler

var portrange = 45032

function getPort (cb) {
  var port = portrange
  portrange += 1

  var server = net.createServer()
  server.listen(port, function (err) {
    server.once('close', function () {
  server.on('error', function (err) {

Listen takes a callback that just adds a listener for "listening", .close() should do the same, adding an event listener for "close".

I'm also debating in my head right now whether the listen callback should take an error. It would be a breaking change, but worth considering.


bnoordhuis commented Feb 16, 2012

Listen takes a callback that just adds a listener for "listening", .close() should do the same, adding an event listener for "close".

Funny coincidence, I was discussing that with @mmalecki last night in #libuv. He couldn't convince me of a pressing need but if it makes the API more consistent without breaking existing code, I'm not against it.

@isaacs isaacs closed this Feb 19, 2012

isaacs commented Feb 19, 2012

Landed on d530ee6. Thanks!

@isaacs isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue Feb 23, 2012

@isaacs isaacs 2012.02.23, Version 0.7.5 (unstable)
* startup speed improvements (Maciej Małecki)

* crypto: add function getDiffieHellman() (Tomasz Buchert)

* buffer: support decoding of URL-safe base64 (Ben Noordhuis)

* Make QueryString.parse() even faster (Brian White)

* url: decode url entities in auth section (Ben Noordhuis)

* http: support PURGE request method (Ben Noordhuis)

* http: Generate Date headers on responses (Mark Nottingham)

* Fix #2762: Add callback to close function. (Mikeal Rogers)

* dgram: fix out-of-bound memory read (Ben Noordhuis)

* repl: add automatic loading of built-in libs (Brandon Benvie)

* repl: remove double calls where possible (Fedor Indutny)

* Readline improvements. Related: #2737 #2756 (Colton Baker)

* build: support shared V8 properly (T.C. Hollingsworth)

* build: disable -fomit-frame-pointer on solaris (Dave Pacheco)

* build: arch detection improvements (Nathan Rajlich)

* build: Make a fat binary for the OS X `make pkg`. (Nathan Rajlich)

* jslint src/ and lib/ on 'make test' (isaacs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment