From 27383de79ea84467bfa0fb52d3359f9df9580ae9 Mon Sep 17 00:00:00 2001 From: zenzhu Date: Sun, 11 Dec 2016 10:33:18 +0800 Subject: [PATCH 1/2] Tweak callback throw error --- lib/detect-port.js | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) 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", From cb201309b6628f40f74bb1c7c4c03086318a497f Mon Sep 17 00:00:00 2001 From: zenzhu Date: Sun, 11 Dec 2016 10:52:44 +0800 Subject: [PATCH 2/2] Add change detail --- HISTORY.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 3c2a164..0a41832 100644 --- a/HISTORY.md +++ b/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