Skip to content

Commit

Permalink
fix: clear pending after stale is refreshed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Aug 11, 2021
1 parent c032e93 commit ee49c03
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/memoize/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ function memoize (
return done(data.value)
}

if (isExpired) keyv.delete(key)
const promise = refreshValue(key, args)

promise.catch(error => (info.staleError = error))

if (isStale) return done(data.value)
if (isStale) {
promise
.then(() => (pending[key] = undefined))
.catch(error => (info.staleError = error))
return done(data.value)
}

try {
const value = await promise
Expand Down

0 comments on commit ee49c03

Please sign in to comment.