diff --git a/lib/caching.js b/lib/caching.js index e348a4d..266b987 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -48,17 +48,24 @@ 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]); + self.queues[key].forEach(function (done) { + done.call(null, work_args[0]); + }); + 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 { + self.queues[key].forEach(function (done) { + done.apply(null, work_args); + }); } - - self.queues[key].forEach(function (done) { - done.apply(null, work_args); - }); delete self.queues[key]; });