diff --git a/lib/routes/pixiv/token.js b/lib/routes/pixiv/token.js index 8a3ccf99583ca4..f00067b6cee80f 100644 --- a/lib/routes/pixiv/token.js +++ b/lib/routes/pixiv/token.js @@ -48,11 +48,27 @@ async function tickToken() { } } -module.exports = async () => { - if (!token) { - await tickToken(); +let tickTokenStarted = false; + +async function startTickToken() { + if (!tickTokenStarted) { + // 如果tickToken没启动 + tickTokenStarted = true; + await tickToken(); // 启动tickToken + } +} + +async function waitForToken() { + while (!token) { + // eslint-disable-next-line no-await-in-loop + await new Promise((resolve) => setTimeout(resolve, 0)); } return token; +} + +module.exports = async () => { + await startTickToken(); + return waitForToken(); }; module.exports.tickToken = tickToken;