http-party / node-portfinder

A simple tool to find an open port or domain socket on the current machine
https://github.com/http-party/node-portfinder
Other
887 stars 95 forks source link

Promise support #51

Closed jucrouzet closed 7 years ago

jucrouzet commented 7 years ago

Adds getPortPromise() which returns a Promise to the next available port :

  const portfinder = require('portfinder');

  portfinder.getPortPromise()
    .then((port) => {
        //
        // `port` is guaranteed to be a free port
        // in this scope.
        //
    })
    .catch((err) => {
        //
        // Could not get a free port, `err` contains the reason.
        //
    });
eriktrom commented 7 years ago

thanks @jucrouzet - I'll take a close look

i really appreciate the pull request - if it takes me more than a day or so for me to review its cause there are a number of downstream deps and we just have to be careful due to that

jucrouzet commented 7 years ago

Done. I'm also not for including Bluebird, for a LOT of reason.

jucrouzet commented 7 years ago

For the downstream deps, that's what came first to my mind, that's why I added a new method instead of modifying the getPort() method to return a promise when called with no callback. BTW, I forgot the TS definition, done.

jucrouzet commented 7 years ago

Hi, I've check all my projects using portfinder (~30). They're all doing good with this PR, (some uses it bare, some use it with bluebird's promisify).

Let me know if there is something to change.

eriktrom commented 7 years ago

@jucrouzet - yes this is fine - thanks for adding it to the README and fixing up the error

eriktrom commented 7 years ago

published to npm