Skip to content

Commit

Permalink
Refactor getCacheCallback to directly use parent promise's resolve an…
Browse files Browse the repository at this point in the history
…d reject, simplifying error handling and avoiding nested promises.
  • Loading branch information
sunil-lakshman committed Jan 23, 2025
1 parent be96351 commit 3a2aef1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/core/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,20 @@ export function sendRequest(queryObject, options) {
}
}

let getCacheCallback = function() {
let getCacheCallback = function(resolve, reject) {
return function(err, entries) {
return new Promise(function(resolve, reject) {
try {
if (err) reject(err);
if (!tojson) entries = resultWrapper(entries);
resolve(spreadResult(entries));
} catch (e) {
reject(e)
try {
if (err) {
return reject(err); // Propagate the error to the parent promise
}
});
}
}
if (!tojson) entries = resultWrapper(entries);
resolve(spreadResult(entries)); // Propagate the result to the parent promise
} catch (e) {
reject(e); // Handle any synchronous errors
}
};
};


let callback = function(continueFlag, resolve, reject) {
if (continueFlag) {
Expand Down Expand Up @@ -339,11 +340,12 @@ export function sendRequest(queryObject, options) {
}.bind(self))
.catch(function(error) {
if (cachePolicy === 2 && self.provider !== null) {
self.provider.get(hashQuery, getCacheCallback());
self.provider.get(hashQuery, getCacheCallback(resolve, reject));
} else {
return reject(error);
reject(error);
}
});

}
}
switch (cachePolicy) {
Expand Down

0 comments on commit 3a2aef1

Please sign in to comment.