@@ -121,18 +121,12 @@ exports.basePath = '/tmp/portfinder'
121121//
122122exports . setBasePath = function ( path ) {
123123 exports . basePath = path ;
124- }
124+ } ;
125125
126- // ### function getPort (options, callback)
127- // #### @options {Object} Settings to use when finding the necessary port
128- // #### @callback {function } Continuation to respond to when complete.
129- // Responds with a unbound port on the current machine.
130- //
131- exports . getPort = function ( options , callback ) {
126+ internals . getPort = function ( options , callback ) {
132127 if ( ! callback ) {
133128 callback = options ;
134129 options = { } ;
135-
136130 }
137131
138132 options . port = Number ( options . port ) || Number ( exports . basePort ) ;
@@ -220,33 +214,39 @@ exports.getPort = function (options, callback) {
220214 } ) ;
221215} ;
222216
223- //
224- // ### function getPortPromise (options)
217+ // ### function getPort (options, callback)
225218// #### @options {Object} Settings to use when finding the necessary port
226- // Responds a promise to an unbound port on the current machine.
219+ // #### @callback {function } Continuation to respond to when complete.
220+ // Responds with a unbound port on the current machine.
227221//
228- exports . getPortPromise = function ( options ) {
229- if ( ! options ) {
222+ exports . getPort = function ( options , callback ) {
223+ if ( ! callback ) {
224+ callback = options ;
230225 options = { } ;
231226 }
232- return new Promise ( function ( resolve , reject ) {
233- exports . getPort ( options , function ( err , port ) {
234- if ( err ) {
235- return reject ( err ) ;
236- }
237- resolve ( port ) ;
227+
228+ if ( ! callback ) {
229+ return new Promise ( function ( resolve , reject ) {
230+ internals . getPort ( options , function ( err , port ) {
231+ if ( err ) {
232+ return reject ( err ) ;
233+ }
234+ resolve ( port ) ;
235+ } ) ;
238236 } ) ;
239- } ) ;
240- }
237+ } else {
238+ return internals . getPort ( options , callback ) ;
239+ }
240+ } ;
241241
242242//
243- // ### function getPorts (count, options, callback)
244- // #### @count {Number} The number of ports to find
243+ // ### function getPortPromise (options)
245244// #### @options {Object} Settings to use when finding the necessary port
246- // #### @callback {function } Continuation to respond to when complete.
247- // Responds with an array of unbound ports on the current machine.
245+ // Responds a promise to an unbound port on the current machine.
248246//
249- exports . getPorts = function ( count , options , callback ) {
247+ exports . getPortPromise = exports . getPort ;
248+
249+ internals . getPorts = function ( count , options , callback ) {
250250 if ( ! callback ) {
251251 callback = options ;
252252 options = { } ;
@@ -270,24 +270,39 @@ exports.getPorts = function (count, options, callback) {
270270} ;
271271
272272//
273- // ### function getPortPromise ( options)
273+ // ### function getPorts (count, options, callback )
274274// #### @count {Number} The number of ports to find
275275// #### @options {Object} Settings to use when finding the necessary port
276- // Responds with a promise that resolves to an array of unbound ports on the current machine.
276+ // #### @callback {function } Continuation to respond to when complete.
277+ // Responds with an array of unbound ports on the current machine.
277278//
278- exports . getPortsPromise = function ( count , options ) {
279- if ( ! options ) {
279+ exports . getPorts = function ( count , options , callback ) {
280+ if ( ! callback ) {
281+ callback = options ;
280282 options = { } ;
281283 }
282- return new Promise ( function ( resolve , reject ) {
283- exports . getPorts ( count , options , function ( err , ports ) {
284- if ( err ) {
285- return reject ( err ) ;
286- }
287- resolve ( ports ) ;
284+
285+ if ( ! callback ) {
286+ return new Promise ( function ( resolve , reject ) {
287+ internals . getPorts ( count , options , function ( err , ports ) {
288+ if ( err ) {
289+ return reject ( err ) ;
290+ }
291+ resolve ( ports ) ;
292+ } ) ;
288293 } ) ;
289- } ) ;
290- }
294+ } else {
295+ return internals . getPorts ( count , options , callback ) ;
296+ }
297+ } ;
298+
299+ //
300+ // ### function getPortPromise (options)
301+ // #### @count {Number} The number of ports to find
302+ // #### @options {Object} Settings to use when finding the necessary port
303+ // Responds with a promise that resolves to an array of unbound ports on the current machine.
304+ //
305+ exports . getPortsPromise = exports . getPorts ;
291306
292307//
293308// ### function getSocket (options, callback)
0 commit comments