Skip to content

Commit

Permalink
Merge pull request #12 from node-modules/tweak-promise
Browse files Browse the repository at this point in the history
Tweak callback throw error
  • Loading branch information
xudafeng committed Dec 11, 2016
2 parents 36833e8 + cb20130 commit 3563702
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
@@ -1,3 +1,8 @@
# 1.0.7 / 2016-12-11

* Early return for rejected promise
* Prevent promsie swallow in callback

# 1.0.6 / 2016-11-29

* Bump version for new Repo
Expand Down
10 changes: 5 additions & 5 deletions lib/detect-port.js
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "detect-port",
"version": "1.0.6",
"version": "1.0.7",
"description": "detect available port",
"keywords": [
"detect",
Expand Down

0 comments on commit 3563702

Please sign in to comment.