Browse Source

check that waiting queue exists before calling forEach on it (#69)

develop
Bryan Donovan 9 years ago
parent
commit
4e812963ae
  1. 8
      lib/callback_filler.js
  2. 13
      test/caching.unit.js

8
lib/callback_filler.js

@ -6,9 +6,11 @@ CallbackFiller.prototype.fill = function(key, err, data) {
var waiting = this.queues[key];
delete this.queues[key];
waiting.forEach(function(task) {
(task.cb)(err, data);
});
if (waiting && waiting.length) {
waiting.forEach(function(task) {
(task.cb)(err, data);
});
}
};
CallbackFiller.prototype.has = function(key) {

13
test/caching.unit.js

@ -515,6 +515,19 @@ describe("caching", function() {
});
});
context("when callback called twice by client", function() {
it("it does not throw an error", function(done) {
cache.wrap(key, function(cb) {
methods.getWidget(name, cb);
methods.getWidget(name, cb);
}, opts, function(err, widget) {
checkErr(err);
assert.deepEqual(widget, {name: name});
setTimeout(done, 10);
});
});
});
it("lets us make nested calls", function(done) {
function getCachedWidget(name, cb) {
cache.wrap(key, function(cacheCb) {

Loading…
Cancel
Save