async function mouted() {
try {
await tryToGetBridgeInfo();
}catch(e
) {
console
.log(e
.message
, 23232)
}
await query();
}
mouted();
async function tryToGetBridgeInfo() {
return new Promise(async (resolve
, reject
) => {
let count
= 0;
let timer
= setInterval(async () => {
count
++;
if (count
>= 6) {
clearInterval(timer
);
return reject(new Error('请求次数超限'))
}
console
.log(`当前是第${count}次请求`)
await getBridgeInfo(count
);
clearInterval(timer
);
resolve();
}, 500);
})
}
async function getBridgeInfo(askCount
) {
return new Promise((resolve
, reject
) => {
console
.log('准备请求桥连接')
let linkSuccessNeedCount
= 4;
if (askCount
< linkSuccessNeedCount
) {
return reject('桥连接失败');
}
console
.log('桥连接成功')
resolve('桥连接成功')
})
}
async function query() {
setTimeout(() => {
console
.log("获取到的接口数据", [{
id
: 1
}])
}, 0)
}
转载请注明原文地址:https://tech.qufami.com/read-23502.html