Skip to content

Commit

Permalink
getPorts
Browse files Browse the repository at this point in the history
  • Loading branch information
charlierudolph committed Feb 6, 2015
1 parent 63718d3 commit 4b39761
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/portfinder.js
Expand Up @@ -67,6 +67,36 @@ exports.getPort = function (options, callback) {
options.server.listen(options.port, options.host);
};

//
// ### function getPorts (count, options, callback)
// #### @count {Number} The number of ports to find
// #### @options {Object} Settings to use when finding the necessary port
// #### @callback {function} Continuation to respond to when complete.
// Responds with an array of unbound ports on the current machine.
//
exports.getPorts = function (count, options, callback) {
if (!callback) {
callback = options;
options = {};
}

var lastPort = null;
async.timesSeries(count, function(index, asyncCallback) {
if (lastPort) {
options.port = exports.nextPort(lastPort);
}

exports.getPort(options, function (err, port) {
if (err) {
asyncCallback(err);
} else {
lastPort = port;
asyncCallback(null, port);
}
});
}, callback);
};

//
// ### function getSocket (options, callback)
// #### @options {Object} Settings to use when finding the necessary port
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,10 +9,10 @@
},
"keywords": ["http", "ports", "utilities"],
"dependencies": {
"async": "0.9.0",
"mkdirp": "0.0.x"
},
"devDependencies": {
"async": "0.1.x",
"vows": "0.5.x"
},
"main": "./lib/portfinder",
Expand Down

0 comments on commit 4b39761

Please sign in to comment.