美文网首页
JS轮询查找接口

JS轮询查找接口

作者: RadishHuang | 来源:发表于2021-09-17 13:08 被阅读0次

    // 轮询查找用户的订单支付状态
  const statueInfo = await getPayStatus(`${orderInfo.data.orderNumberStr}`).catch(res => res);


const getPayStatus = async (orderNumber) => { // 轮询查找订单状态
  let counter = 0;
  const MAXCOUNTER = 3;
  return new Promise((resolve) => {
    const loopFun = async () => {
      if (counter > MAXCOUNTER) {
        resolve(false);
      } else {
        counter++;
        const payInfo = await paySatus({ orderNumber, noLoading: true }).catch(res => res);
        console.log(' === payinfo ==', payInfo);
        if (payInfo?.data?.status && parseInt(payInfo.data.status) === 2) {
          resolve(true);
        } else {
          setTimeout(() => {
            loopFun();
          }, 1000)
        }
      }
    }
    loopFun();
  })
};

相关文章

网友评论

      本文标题:JS轮询查找接口

      本文链接:https://www.haomeiwen.com/subject/ngwjgltx.html