It takes too much time for Mini Program to get token, but the home page is a request that needs token. Is there any good way to solve it?

you need to use some information in openid and userinfo to obtain token, so app.js needs to wait for these two APIs to get data before sending a request to acquire token. But what if you need to send a request and need token, as soon as you enter Mini Program"s home page, but what if you haven"t got token yet?
my current practice is to load wx.showLoading for three seconds in onLoad when I enter the home page, and then perform the operation, but sometimes I can"t guarantee that three seconds is enough. Is there a better way

Mar.14,2022

my current practice is to make a judgment every 200ms (the specific time is set by myself), to determine whether the token, has been obtained, and to make a request if yes, instead of waiting for 200 more. You can solve this problem. The specific time is related to performance. The shorter the time is, the faster the response is, but the performance is not so good. The longer the time is, the slower the response is, but the better the performance is. It is said on the Internet that you can use Promise to achieve asynchrony into Synchronize, but you need to introduce js, to see how you choose.

Menu