Skip to content

Commit 427ac6a

Browse files
committed
Merge pull request jaredwray#48 from theorm/bugfix/wrap-callback
Triggering callback in wrap after it was queued
2 parents bdfcbc2 + e9c4f0a commit 427ac6a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/caching.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ var caching = function(args) {
107107
}
108108

109109
if (!self._isCacheableValue(data)) {
110-
return cb();
110+
callbackFiller.fill(key, null, data);
111+
return;
111112
}
112113

113114
self.store.set(key, data, options, function(err) {

test/caching.unit.js

+21
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,27 @@ describe("caching", function() {
688688
});
689689
});
690690
});
691+
692+
context("when wrapped function returns a non cacheable value once", function() {
693+
it("second call to 'wrap' triggers the callback", function(done) {
694+
var key = support.random.string();
695+
696+
// 1.
697+
cache.wrap(key, function(cb) {
698+
cb(null, undefined);
699+
}, function(err, result) {
700+
assert.equal(result, undefined);
701+
});
702+
703+
// 2.
704+
cache.wrap(key, function(cb) {
705+
cb(null, undefined);
706+
}, function(err, result) {
707+
assert.equal(result, undefined);
708+
done();
709+
});
710+
});
711+
});
691712
});
692713

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

0 commit comments

Comments
 (0)