Skip to content

Commit

Permalink
Allow passing in a promise dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidhartha Chatterjee committed May 24, 2016
1 parent 290f70f commit d6f8c67
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

"predef" : [ // Extra globals.
"__dirname",
"Promise",
"Buffer",
"event",
"exports",
Expand Down
2 changes: 2 additions & 0 deletions lib/caching.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var caching = function(args) {
// do we handle a cache error the same as a cache miss?
self.ignoreCacheErrors = args.ignoreCacheErrors || false;

var Promise = args.promiseDependency || global.Promise;

var callbackFiller = new CallbackFiller();

if (typeof args.isCacheableValue === 'function') {
Expand Down
2 changes: 2 additions & 0 deletions lib/multi_caching.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var multiCaching = function(caches, options) {
var self = {};
options = options || {};

var Promise = options.promiseDependency || global.Promise;

if (!Array.isArray(caches)) {
throw new Error('multiCaching requires an array of caches');
}
Expand Down
1 change: 1 addition & 0 deletions lib/stores/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var memoryStore = function(args) {
args = args || {};
var self = {};
self.name = 'memory';
var Promise = args.promiseDependency || global.Promise;
self.usePromises = (typeof Promise === 'undefined' || args.noPromises) ? false : true;

var ttl = args.ttl;
Expand Down
4 changes: 3 additions & 1 deletion test/caching.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var checkErr = support.checkErr;
var caching = require('../index').caching;
var memoryStore = require('../lib/stores/memory');

var Promise = require('es6-promise').Promise;

var methods = {
getWidget: function(name, cb) {
process.nextTick(function() {
Expand All @@ -27,7 +29,7 @@ describe("caching", function() {
['memory'].forEach(function(store) {
context("using " + store + " store", function() {
beforeEach(function() {
cache = caching({store: store});
cache = caching({store: store, promiseDependency: Promise});
key = support.random.string(20);
value = support.random.string();
});
Expand Down
8 changes: 5 additions & 3 deletions test/multi_caching.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var caching = require('../index').caching;
var multiCaching = require('../index').multiCaching;
var memoryStore = require('../lib/stores/memory');

var Promise = require('es6-promise').Promise;

var methods = {
getWidget: function(name, cb) {
process.nextTick(function() {
Expand All @@ -29,9 +31,9 @@ describe("multiCaching", function() {
memoryTtl = 0.1;
defaultTtl = 5;

memoryCache = caching({store: 'memory', ttl: memoryTtl});
memoryCache2 = caching({store: 'memory', ttl: memoryTtl});
memoryCache3 = caching({store: 'memory', ttl: memoryTtl});
memoryCache = caching({store: 'memory', ttl: memoryTtl, promiseDependency: Promise});
memoryCache2 = caching({store: 'memory', ttl: memoryTtl, promiseDependency: Promise});
memoryCache3 = caching({store: 'memory', ttl: memoryTtl, promiseDependency: Promise});

key = support.random.string(20);
name = support.random.string();
Expand Down
4 changes: 0 additions & 4 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ var Mocha = require('mocha');
var optimist = require('optimist');
var walkDir = require('./support').walkDir;

if (typeof Promise === "undefined") {
global.Promise = require('es6-promise').Promise;
}

var argv = optimist
.usage("Usage: $0 -t [types] --reporter [reporter] --timeout [timeout]")['default'](
{types: 'unit,functional', reporter: 'spec', timeout: 6000})
Expand Down

0 comments on commit d6f8c67

Please sign in to comment.