From 03c00b2d7055585f6b36b30d652ea224896156b3 Mon Sep 17 00:00:00 2001 From: Bryan Donovan Date: Sun, 15 Jun 2014 10:42:56 -0700 Subject: [PATCH] allow calling memory store get() without callback --- lib/stores/memory.js | 11 ++++++++--- test/caching.unit.js | 9 ++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/stores/memory.js b/lib/stores/memory.js index 7d2acd8..1b02648 100644 --- a/lib/stores/memory.js +++ b/lib/stores/memory.js @@ -20,9 +20,14 @@ var memory_store = function (args) { }; self.get = function (key, cb) { - process.nextTick(function () { - cb(null, lru_cache.get(key)); - }); + var value = lru_cache.get(key); + if (cb) { + process.nextTick(function () { + cb(null, value); + }); + } else { + return value; + } }; self.del = function (key, cb) { diff --git a/test/caching.unit.js b/test/caching.unit.js index a7c1dd1..5f1f5dc 100644 --- a/test/caching.unit.js +++ b/test/caching.unit.js @@ -40,13 +40,12 @@ describe("caching", function () { }); }); - it("lets us set data without a callback", function (done) { + it("lets us set and get data without a callback", function (done) { cache.set(key, value); setTimeout(function () { - cache.get(key, function (err, result) { - assert.equal(result, value); - done(); - }); + var result = cache.get(key); + assert.equal(result, value); + done(); }, 20); }); });