From 1e5cd0f9357431b0590c75e0857dc316fb329a0c Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Thu, 18 Sep 2014 10:04:39 -0500 Subject: [PATCH 1/3] Execute queued callbacks on error. --- lib/caching.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/caching.js b/lib/caching.js index e348a4d..02b26b0 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -48,7 +48,17 @@ var caching = function (args) { work(function () { var work_args = Array.prototype.slice.call(arguments, 0); if (work_args[0]) { // assume first arg is an error - return cb(work_args[0]); + if (!self.ignoreCacheErrors) { + self.queues[key].forEach(function (done) { + done.apply(null, work_args); + }); + delete self.queues[key]; + } + else { + cb(work_args[0]); + } + + return; } // Subsequently assume second arg is result. self.store.set(key, work_args[1], function (err) { From 8c822668870818b95e52aabc06fc70fb6b807346 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Thu, 18 Sep 2014 10:31:13 -0500 Subject: [PATCH 2/3] Call back on set errors too. --- lib/caching.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/caching.js b/lib/caching.js index 02b26b0..6d9abd1 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -48,27 +48,27 @@ var caching = function (args) { work(function () { var work_args = Array.prototype.slice.call(arguments, 0); if (work_args[0]) { // assume first arg is an error - if (!self.ignoreCacheErrors) { - self.queues[key].forEach(function (done) { - done.apply(null, work_args); - }); - delete self.queues[key]; - } - else { - cb(work_args[0]); - } - + self.queues[key].forEach(function (done) { + done.apply(null, work_args); + }); + delete self.queues[key]; return; } // Subsequently assume second arg is result. self.store.set(key, work_args[1], function (err) { if (err && (!self.ignoreCacheErrors)) { - return cb(err); + self.queues[key].forEach(function (done) { + done.call(null, err); + }); + } + else if (!err) { + self.queues[key].forEach(function (done) { + done.apply(null, work_args); + }); + } + else { + return; } - - self.queues[key].forEach(function (done) { - done.apply(null, work_args); - }); delete self.queues[key]; }); From c0d907cbd1d55f32db27df044496a09a53faab8f Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Thu, 18 Sep 2014 10:47:58 -0500 Subject: [PATCH 3/3] Callback with only error if it exists. --- lib/caching.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/caching.js b/lib/caching.js index 6d9abd1..266b987 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -49,7 +49,7 @@ var caching = function (args) { var work_args = Array.prototype.slice.call(arguments, 0); if (work_args[0]) { // assume first arg is an error self.queues[key].forEach(function (done) { - done.apply(null, work_args); + done.call(null, work_args[0]); }); delete self.queues[key]; return; @@ -61,14 +61,11 @@ var caching = function (args) { done.call(null, err); }); } - else if (!err) { + else { self.queues[key].forEach(function (done) { done.apply(null, work_args); }); } - else { - return; - } delete self.queues[key]; });