Skip to content

Commit

Permalink
v4.0.2: fix rejecting queued promises
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Aug 19, 2021
1 parent 1030994 commit 1823c74
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 13 deletions.
10 changes: 7 additions & 3 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ let cache = function ({ call, key, expires = 0 }) {

// get existing promise (of a previous pending request asking for the exact same thing)
let existingPromise = getPromise({ key });
if(existingPromise) { return existingPromise.then((value)=>{
return resolve(value)
}) }
if(existingPromise) {
return existingPromise
.then(resolve)
.catch(reject)
}

setPromise({ key, promise: new Promise((resolveQueue, rejectQueue)=>{
if (expires === 0) {
Expand Down Expand Up @@ -104,6 +106,8 @@ let cache = function ({ call, key, expires = 0 }) {
})
}).then(()=>{
deletePromise({ key });
}).catch(()=>{
deletePromise({ key });
});
})
};
Expand Down
10 changes: 7 additions & 3 deletions dist/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ let cache = function ({ call, key, expires = 0 }) {

// get existing promise (of a previous pending request asking for the exact same thing)
let existingPromise = getPromise({ key });
if(existingPromise) { return existingPromise.then((value)=>{
return resolve(value)
}) }
if(existingPromise) {
return existingPromise
.then(resolve)
.catch(reject)
}

setPromise({ key, promise: new Promise((resolveQueue, rejectQueue)=>{
if (expires === 0) {
Expand Down Expand Up @@ -100,6 +102,8 @@ let cache = function ({ call, key, expires = 0 }) {
})
}).then(()=>{
deletePromise({ key });
}).catch(()=>{
deletePromise({ key });
});
})
};
Expand Down
10 changes: 7 additions & 3 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@

// get existing promise (of a previous pending request asking for the exact same thing)
let existingPromise = getPromise({ key });
if(existingPromise) { return existingPromise.then((value)=>{
return resolve(value)
}) }
if(existingPromise) {
return existingPromise
.then(resolve)
.catch(reject)
}

setPromise({ key, promise: new Promise((resolveQueue, rejectQueue)=>{
if (expires === 0) {
Expand Down Expand Up @@ -103,6 +105,8 @@
})
}).then(()=>{
deletePromise({ key });
}).catch(()=>{
deletePromise({ key });
});
})
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "depay-web3-client",
"moduleName": "Web3Client",
"version": "4.0.1",
"version": "4.0.2",
"description": "A web3 client to fetch blockchain data just like we are used to with http clients.",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
Expand Down
10 changes: 7 additions & 3 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ let cache = function ({ call, key, expires = 0 }) {

// get existing promise (of a previous pending request asking for the exact same thing)
let existingPromise = getPromise({ key })
if(existingPromise) { return existingPromise.then((value)=>{
return resolve(value)
}) }
if(existingPromise) {
return existingPromise
.then(resolve)
.catch(reject)
}

setPromise({ key, promise: new Promise((resolveQueue, rejectQueue)=>{
if (expires === 0) {
Expand Down Expand Up @@ -97,6 +99,8 @@ let cache = function ({ call, key, expires = 0 }) {
})
}).then(()=>{
deletePromise({ key })
}).catch(()=>{
deletePromise({ key })
})
})
}
Expand Down
11 changes: 11 additions & 0 deletions tests/units/bsc/request/cache.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/units/ethereum/request/cache.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1823c74

Please sign in to comment.