From e9c4f0af2a7e1f14eeb91691a8dcbb757f03f662 Mon Sep 17 00:00:00 2001 From: theorm Date: Mon, 18 Apr 2016 14:34:33 +0700 Subject: [PATCH] Fixed triggering callback in wrap after it was queued --- lib/caching.js | 3 ++- test/caching.unit.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/caching.js b/lib/caching.js index 7c69e0c..af2dc93 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -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) { diff --git a/test/caching.unit.js b/test/caching.unit.js index c3c11da..394ee4d 100644 --- a/test/caching.unit.js +++ b/test/caching.unit.js @@ -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() {