Skip to content

Commit

Permalink
Merge pull request #48 from theorm/bugfix/wrap-callback
Browse files Browse the repository at this point in the history
Triggering callback in wrap after it was queued
  • Loading branch information
BryanDonovan committed Apr 18, 2016
2 parents bdfcbc2 + e9c4f0a commit 427ac6a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/caching.js
Expand Up @@ -107,7 +107,8 @@ var caching = function(args) {
}

if (!self._isCacheableValue(data)) {
return cb();
callbackFiller.fill(key, null, data);
return;
}

self.store.set(key, data, options, function(err) {
Expand Down
21 changes: 21 additions & 0 deletions test/caching.unit.js
Expand Up @@ -688,6 +688,27 @@ describe("caching", function() {
});
});
});

context("when wrapped function returns a non cacheable value once", function() {
it("second call to 'wrap' triggers the callback", function(done) {
var key = support.random.string();

// 1.
cache.wrap(key, function(cb) {
cb(null, undefined);
}, function(err, result) {
assert.equal(result, undefined);
});

// 2.
cache.wrap(key, function(cb) {
cb(null, undefined);
}, function(err, result) {
assert.equal(result, undefined);
done();
});
});
});
});

describe("when called multiple times in parallel with same key", function() {
Expand Down

0 comments on commit 427ac6a

Please sign in to comment.