Skip to content

Commit

Permalink
fix: retry finding port when port is null and get ports in sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 7, 2019
1 parent df25433 commit 150b164
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 165 deletions.
23 changes: 17 additions & 6 deletions lib/utils/findPort.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
'use strict';

const { getPortPromise } = require('portfinder');
const pRetry = require('p-retry');
const portfinder = require('portfinder');
const defaultPort = require('./defaultPort');
const defaultTo = require('./defaultTo');
const tryParseInt = require('./tryParseInt');

function runPortFinder() {
return new Promise((resolve, reject) => {
portfinder.basePort = defaultPort;
portfinder.getPort((error, port) => {
if (error) {
return reject(error);
}

return resolve(port);
});
});
}

function findPort(port) {
if (typeof port !== 'undefined') {
if (port) {
return Promise.resolve(port);
}

Expand All @@ -19,10 +33,7 @@ function findPort(port) {
3
);

return getPortPromise({
port: defaultPort,
stopPort: defaultPort + defaultPortRetry,
});
return pRetry(runPortFinder, { retries: defaultPortRetry });
}

module.exports = findPort;
Loading

0 comments on commit 150b164

Please sign in to comment.