Browse Source

Merge pull request #10 from elliotttf/callback-on-error

Prevent stalemate by executing callbacks on error
feature/nested-cache-fetch-fix
Bryan Donovan 10 years ago
parent
commit
bd1036175c
  1. 19
      lib/caching.js

19
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];
});

Loading…
Cancel
Save