Skip to content

Commit

Permalink
fix: remove Promise.finally
Browse files Browse the repository at this point in the history
  • Loading branch information
brickspert committed Dec 20, 2021
1 parent f985ed7 commit 7a76ae3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/hooks/src/useRequest/src/utils/cachePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ const setCachePromise = (cacheKey: CachedKey, promise: Promise<any>) => {
// Because the promise.finally will change the reference of the promise
cachePromise.set(cacheKey, promise);

promise.finally(() => {
cachePromise.delete(cacheKey);
});
// no use promise.finally for compatibility
promise
.then((res) => {
cachePromise.delete(cacheKey);
return res;
})
.catch((err) => {
cachePromise.delete(cacheKey);
throw err;
});
};

export { getCachePromise, setCachePromise };

0 comments on commit 7a76ae3

Please sign in to comment.