Skip to content

Commit

Permalink
1. Fix: fix issue run in node 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
itestauipi committed Jan 9, 2017
1 parent 60a863c commit c8cf4a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Expand Up @@ -4,14 +4,16 @@ language: node_js
node_js:
- "4.2"
- "5.0"

- "6.0"
- "7.0"

cache:
directories:
- node_modules

matrix:
fast_finish: true

script: "grunt"

after_success: istanbul-coveralls
after_success: istanbul-coveralls
4 changes: 4 additions & 0 deletions CHANGE.md
@@ -1,6 +1,10 @@
PromiseClass change log
====================

## ver 1.0.3 (2017-1-9)

1. Fix: fix issue run in node 7.x

## ver 1.0.2 (2016-12-20)

1. Fix: fix issue when catch error by promise
Expand Down
72 changes: 36 additions & 36 deletions lib/promiseclass.js
Expand Up @@ -54,48 +54,48 @@ const PromiseClass = {
let self = this;
let args = Array.prototype.slice.call(arguments, 0);
let isAsync = /(\(|,)\s*(done|callback|cb)\s*\)\s*\{/i.test(fn);
let deferred = ChainPromise.defer();
let promise = deferred.promise;
let callback;
if(isCallback(args[args.length - 1])){
// async mode
callback = args.pop();
}
function done(error, ret){
if(callback){
let newRet = callback.call(self, error, ret);
if(isGenerator(newRet)){
// support callback generator
newRet = co(newRet);
var promise = new ChainPromise(function(resolve, reject){
let callback;
if(isCallback(args[args.length - 1])){
// async mode
callback = args.pop();
}
function done(error, ret){
if(callback){
let newRet = callback.call(self, error, ret);
if(isGenerator(newRet)){
// support callback generator
newRet = co(newRet);
}
resolve(newRet);
}
else{
error ? reject(error) : resolve(ret);
}
deferred.resolve(newRet);
}
else{
error ? deferred.reject(error) : deferred.resolve(ret);
// async modem hook done
if(isAsync){
args.push(done);
}
}
// async modem hook done
if(isAsync){
args.push(done);
}
try{
let ret = fn.apply(self, args);
// sync mode
if(isAsync === false){
if(ret !== undefined && isGenerator(ret)){
// support method generator
co(ret).then(function(ret){
try{
let ret = fn.apply(self, args);
// sync mode
if(isAsync === false){
if(ret !== undefined && isGenerator(ret)){
// support method generator
co(ret).then(function(ret){
done(null, ret);
}).catch(done);
}
else{
done(null, ret);
}).catch(done);
}
else{
done(null, ret);
}
}
}
}
catch(error){
done(error);
}
catch(error){
done(error);
}
});
promise._context = self;
return promise;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "promiseclass",
"version": "1.0.2",
"version": "1.0.3",
"description": "Create Promise chain Class",
"main": "./index",
"dependencies": {
Expand Down

0 comments on commit c8cf4a6

Please sign in to comment.