Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

.close() should take a callback. #2762

Closed
mikeal opened this issue Feb 16, 2012 · 2 comments
Closed

.close() should take a callback. #2762

mikeal opened this issue Feb 16, 2012 · 2 comments
Labels

Comments

@mikeal
Copy link

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 () {
      cb(port)
    })
    server.close()
  })
  server.on('error', function (err) {
    getPort(cb)
  })
}

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
Copy link
Member

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
Copy link

isaacs commented Feb 19, 2012

Landed on d530ee6. Thanks!

isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue Feb 23, 2012
* 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 nodejs#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: nodejs#2737 nodejs#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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants