diff --git a/lib/detect-port.js b/lib/detect-port.js index 891534a..6dff69d 100644 --- a/lib/detect-port.js +++ b/lib/detect-port.js @@ -7,13 +7,13 @@ module.exports = function() { const promise = new Promise((resolve, reject) => { if (!args.length) { - reject('wrong number of arguments'); + return reject('wrong number of arguments'); } const port = parseInt(args[0], 10); if (isNaN(port)) { - reject(`wrong type of arguments with: '${args[0]}'`); + return reject(`wrong type of arguments with: '${args[0]}'`); } const loop = port => { @@ -63,9 +63,9 @@ module.exports = function() { const cb = args[1]; promise.then(data => { - cb.call(this, null, data); - }).catch(err => { - cb.call(this, err); + process.nextTick(cb.bind(null, null, data)); + }, err => { + process.nextTick(cb.bind(null, err)); }); } else { return promise; diff --git a/package.json b/package.json index c4d6997..cc8e59a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "detect-port", - "version": "1.0.6", + "version": "1.0.7", "description": "detect available port", "keywords": [ "detect",