Return promise correctly for get calls (#3862)

This commit is contained in:
Shefali Joshi 2021-05-05 15:23:49 -07:00 committed by GitHub
parent 0da35a44b0
commit 05f9202fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -161,6 +161,7 @@ ObjectAPI.prototype.addProvider = function (namespace, provider) {
ObjectAPI.prototype.get = function (identifier, abortSignal) { ObjectAPI.prototype.get = function (identifier, abortSignal) {
let keystring = this.makeKeyString(identifier); let keystring = this.makeKeyString(identifier);
if (this.cache[keystring] !== undefined) { if (this.cache[keystring] !== undefined) {
return this.cache[keystring]; return this.cache[keystring];
} }
@ -176,15 +177,16 @@ ObjectAPI.prototype.get = function (identifier, abortSignal) {
throw new Error('Provider does not support get!'); throw new Error('Provider does not support get!');
} }
let objectPromise = provider.get(identifier, abortSignal); let objectPromise = provider.get(identifier, abortSignal).then(result => {
this.cache[keystring] = objectPromise;
return objectPromise.then(result => {
delete this.cache[keystring]; delete this.cache[keystring];
result = this.applyGetInterceptors(identifier, result); result = this.applyGetInterceptors(identifier, result);
return result; return result;
}); });
this.cache[keystring] = objectPromise;
return objectPromise;
}; };
/** /**