Comparing version 0.3.5 to 0.3.6
@@ -37,7 +37,4 @@ // Support for asynchronous functions | ||
if (waiting[id]) { | ||
if (typeof waiting[id] === 'function') { | ||
waiting[id] = [waiting[id], currentCallback]; | ||
} else { | ||
waiting[id].push(currentCallback); | ||
} | ||
if (typeof waiting[id] === 'function') waiting[id] = [waiting[id], currentCallback]; | ||
else waiting[id].push(currentCallback); | ||
currentCallback = null; | ||
@@ -83,2 +80,7 @@ return; | ||
delete waiting[id]; | ||
if (!cb) { | ||
// Already processed, | ||
// outcome of race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb) | ||
return; | ||
} | ||
args = aFrom(arguments); | ||
@@ -96,5 +98,3 @@ if (conf.has(id)) { | ||
} else { | ||
cb.forEach(function (cb) { | ||
result = apply.call(cb, this, args); | ||
}, this); | ||
cb.forEach(function (cb) { result = apply.call(cb, this, args); }, this); | ||
} | ||
@@ -118,3 +118,9 @@ return result; | ||
} | ||
waiting[id] = currentCallback.cb; | ||
if (waiting[id]) { | ||
// Race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb) | ||
if (typeof waiting[id] === 'function') waiting[id] = [waiting[id], currentCallback.cb]; | ||
else waiting[id].push(currentCallback.cb); | ||
} else { | ||
waiting[id] = currentCallback.cb; | ||
} | ||
delete currentCallback.cb; | ||
@@ -121,0 +127,0 @@ currentCallback.id = id; |
@@ -20,3 +20,3 @@ // Timeout cached values | ||
conf.on('set' + postfix, function (id) { | ||
timeouts[id] = setTimeout(function () { conf.clear(id); }, maxAge); | ||
timeouts[id] = setTimeout(function () { conf.delete(id); }, maxAge); | ||
if (!preFetchTimeouts) return; | ||
@@ -23,0 +23,0 @@ if (preFetchTimeouts[id]) clearTimeout(preFetchTimeouts[id]); |
{ | ||
"name": "memoizee", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"description": "Memoize/cache", | ||
@@ -5,0 +5,0 @@ "author": "Mariusz Nowak <medikoo@medikoo.com> (http://www.medikoo.com/)", |
@@ -153,3 +153,3 @@ # Memoize | ||
}; | ||
Object.definePropeties(Foo.prototype, memoizeMethods({ | ||
Object.defineProperties(Foo.prototype, memoizeMethods({ | ||
bar: d(function () { | ||
@@ -156,0 +156,0 @@ // ... method logic |
@@ -254,4 +254,25 @@ 'use strict'; | ||
}); | ||
}, | ||
"Sync Clear: Primitive": function (a, d) { | ||
var mfn, fn; | ||
fn = function (x, cb) { | ||
nextTick(function () { | ||
cb(null, x); | ||
}); | ||
}; | ||
mfn = memoize(fn, { async: true, primitive: true }); | ||
mfn(2, function (err, i) { | ||
a(i, 2, "First"); | ||
}); | ||
mfn(1, function (err, i) { | ||
a(i, 1, "Second"); | ||
nextTick(d); | ||
}); | ||
mfn.clear(); | ||
mfn(2, function (err, i) { | ||
a(i, 2, "Third"); | ||
}); | ||
} | ||
}; | ||
}; |
@@ -36,14 +36,19 @@ 'use strict'; | ||
a(mfn(9, 1), 10, "Result: C"); | ||
a(i, 3, "Called: C"); | ||
setTimeout(function () { | ||
a(mfn(3, 7), 10, "Result: Wait After"); | ||
a(i, 3, "Called: Wait After"); | ||
a(i, 4, "Called: Wait After"); | ||
a(mfn(5, 8), 13, "Result: Wait After B"); | ||
a(i, 4, "Called: Wait After B"); | ||
a(i, 5, "Called: Wait After B"); | ||
a(mfn(3, 7), 10, "Result: Wait After #2"); | ||
a(i, 4, "Called: Wait After #2"); | ||
a(i, 5, "Called: Wait After #2"); | ||
a(mfn(5, 8), 13, "Result: Wait After B #2"); | ||
a(i, 4, "Called: Wait After B #2"); | ||
a(i, 5, "Called: Wait After B #2"); | ||
a(mfn(9, 1), 10, "Result: WiatC"); | ||
a(i, 5, "Called: Wait C"); | ||
d(); | ||
}, 100); | ||
}, 90); | ||
}, 20); | ||
@@ -50,0 +55,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132115
3697