Skip to content

Commit

Permalink
Allowing .end()'s callback to not require an err param.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Lokahi Podwys committed Apr 20, 2015
1 parent 5274589 commit 9047ba5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ module.exports = function(superagent, config){
if(this.method === 'GET'){
superagent.cacheService.get(key, function (err, response){
if(!err && response){
cb(err, response, key);
callbackExecutor(cb, err, response, key);
//cb(err, response, key);
}
else{
if(curProps.doQuery){
Expand All @@ -83,17 +84,20 @@ module.exports = function(superagent, config){
}
if(!isEmpty(response) || curProps.cacheWhenEmpty){
superagent.cacheService.set(key, response, curProps.expiration, function(){
cb(err, response, key);
callbackExecutor(cb, err, response, key);
//cb(err, response, key);
});
}
else{
cb(err, response, key);
callbackExecutor(cb, err, response, key);
//cb(err, response, key);
}
}
});
}
else{
cb(null, null, key);
callbackExecutor(cb, null, null, key);
//cb(null, null, key);
}
}
});
Expand All @@ -102,15 +106,17 @@ module.exports = function(superagent, config){
this._end(function (err, response){
if(!err && response){
superagent.cacheService.del(key, function (){
cb(err, response, key);
callbackExecutor(cb, err, response, key);
//cb(err, response, key);
});
}
});
}
}
else{
this._end(function (err, response){
cb(err, response, undefined);
callbackExecutor(cb, err, response, undefined);
//cb(err, response, undefined);
});
}
}
Expand Down Expand Up @@ -211,6 +217,15 @@ module.exports = function(superagent, config){
props = {doQuery: true, cacheWhenEmpty: true};
}

function callbackExecutor(cb, err, result, key){
if(cb.length > 1){
cb(err, result, key);
}
else{
cb(result, key);
}
}

var noop = function(){}

}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "superagent-cache",
"version": "0.1.6",
"version": "0.1.7",
"description": "Superagent with tiered caching provided by cache-service.",
"main": "index.js",
"dependencies": {
"superagent": "1.1.0",
"cache-service": "0.1.4"
"cache-service": "0.1.5"
},
"devDependencies": {
"mocha": "1.13.0",
Expand Down

0 comments on commit 9047ba5

Please sign in to comment.