export const sleep = (timeout = 100) => { return new Promise(resolve => { setTimeout(resolve, timeout) })}// 轮询函数const polling = async (request, times) => { if (times <= 0) { return false; } const result = await request(); if (result) { return true; } await sleep(1000); return polling(request, times - 1);};// 请求主体函数const checkOrder = async orderSn => { const { data: { status }, } = await Axios.get('/mall/order/status', { params: { orderSn }, }) return status === 2}// 调用// 当请求主体函数返回true或者times跑完时候会终止const status = await polling(() => checkOrder(appOrderSn), 3)