compare the speed of reading data from the local cache and the request interface. It doesn"t matter if the local cache returns first, but if the request interface returns first, it will cause the old result of the local cache to replace the new data of the request interface. How can this be avoided?
related codes
//
function getLocal(storageKey) {
return new Promise((resolve, reject) => {
wx.getStorage({
key: storageKey,
success(res) {
resolve(res.data);
},
fail(error) {
reject(error);
},
});
});
}
//
function getRequestApi(options) {
return request({
url: "",
data: {
...options,
}
});
}
//
Promise.race([getLocal("storageKey"), getRequestApi(options)]).then(//);
the above code is that I intend to use Promise.race to make a comparison, but I find that I can only get the data returned first, but I"m not sure which request completed it first. How to solve it?