lru-cache
Advanced tools
Comparing version 7.9.0 to 7.9.1
26
index.js
@@ -621,3 +621,3 @@ const perf = typeof performance === 'object' && performance && | ||
} | ||
const p = Promise.resolve(this.fetchMethod(k, v, fetchOpts)).then(v => { | ||
const cb = v => { | ||
if (!ac.signal.aborted) { | ||
@@ -627,5 +627,16 @@ this.set(k, v, fetchOpts.options) | ||
return v | ||
}) | ||
} | ||
const eb = er => { | ||
if (this.valList[index] === p) { | ||
this.delete(k) | ||
} | ||
if (p.__returned === p) { | ||
throw er | ||
} | ||
} | ||
const pcall = res => res(this.fetchMethod(k, v, fetchOpts)) | ||
const p = new Promise(pcall).then(cb, eb) | ||
p.__abortController = ac | ||
p.__staleWhileFetching = v | ||
p.__returned = null | ||
if (index === undefined) { | ||
@@ -642,3 +653,5 @@ this.set(k, p, fetchOpts.options) | ||
return p && typeof p === 'object' && typeof p.then === 'function' && | ||
Object.prototype.hasOwnProperty.call(p, '__staleWhileFetching') | ||
Object.prototype.hasOwnProperty.call(p, '__staleWhileFetching') && | ||
Object.prototype.hasOwnProperty.call(p, '__returned') && | ||
(p.__returned === p || p.__returned === null) | ||
} | ||
@@ -672,3 +685,4 @@ | ||
if (index === undefined) { | ||
return this.backgroundFetch(k, index, options) | ||
const p = this.backgroundFetch(k, index, options) | ||
return (p.__returned = p) | ||
} else { | ||
@@ -679,3 +693,3 @@ // in cache, maybe already fetching | ||
return allowStale && v.__staleWhileFetching !== undefined | ||
? v.__staleWhileFetching : v | ||
? v.__staleWhileFetching : (v.__returned = v) | ||
} | ||
@@ -695,3 +709,3 @@ | ||
return allowStale && p.__staleWhileFetching !== undefined | ||
? p.__staleWhileFetching : p | ||
? p.__staleWhileFetching : (p.__returned = p) | ||
} | ||
@@ -698,0 +712,0 @@ } |
{ | ||
"name": "lru-cache", | ||
"description": "A cache object that deletes the least-recently-used items.", | ||
"version": "7.9.0", | ||
"version": "7.9.1", | ||
"author": "Isaac Z. Schlueter <i@izs.me>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
50012
796