-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now checks ports before assign to chromy instance
getFreePorts now blocks pMap until a vaid portlist has been validated.
- Loading branch information
Showing
3 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const portfinder = require('portfinder'); | ||
/** | ||
* Gets the free ports. | ||
* | ||
* @param {number} startingPort The starting port | ||
* @param {number} requestedPorts how many ports should we find? | ||
* @return {Array} The free ports. | ||
*/ | ||
module.exports = function getFreePorts(startingPort, requestedPorts) { | ||
return new Promise((resolve, reject) => { | ||
const R = resolve; | ||
console.log(`searching for ${requestedPorts} available ports.`); | ||
const requestedAmount = requestedPorts; | ||
let freePorts = []; | ||
|
||
function findFreePorts(startPort, pointer) { | ||
const PTR = pointer || 1; | ||
// console.log('freePorts > ', PTR, JSON.stringify(freePorts)); | ||
if (PTR > requestedAmount) { | ||
R(freePorts); | ||
return; | ||
} | ||
portfinder.basePort = startPort; | ||
portfinder.getPort(function (err, port) { | ||
if (err) { | ||
reject(new Error(err)); | ||
} | ||
freePorts[PTR-1] = port; | ||
return findFreePorts(port + 1, PTR + 1); | ||
}); | ||
} | ||
findFreePorts(startingPort); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters