From 05f9202fe4ba914d4c9415bb7c9818eb3c4890f6 Mon Sep 17 00:00:00 2001 From: Shefali Joshi Date: Wed, 5 May 2021 15:23:49 -0700 Subject: [PATCH] Return promise correctly for get calls (#3862) --- src/api/objects/ObjectAPI.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index 55e62ee6a6..a19ad50f82 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -161,6 +161,7 @@ ObjectAPI.prototype.addProvider = function (namespace, provider) { ObjectAPI.prototype.get = function (identifier, abortSignal) { let keystring = this.makeKeyString(identifier); + if (this.cache[keystring] !== undefined) { return this.cache[keystring]; } @@ -176,15 +177,16 @@ ObjectAPI.prototype.get = function (identifier, abortSignal) { throw new Error('Provider does not support get!'); } - let objectPromise = provider.get(identifier, abortSignal); - this.cache[keystring] = objectPromise; - - return objectPromise.then(result => { + let objectPromise = provider.get(identifier, abortSignal).then(result => { delete this.cache[keystring]; result = this.applyGetInterceptors(identifier, result); return result; }); + + this.cache[keystring] = objectPromise; + + return objectPromise; }; /**