美文网首页
优雅的轮询

优雅的轮询

作者: 爱代码的派派星 | 来源:发表于2019-10-18 11:18 被阅读0次
    async resultFun(key) {
          try {
            const res = await base.ajaxGet(API.EXCHANGE_RESULT, {
              key: key
            });
            return res.data.id;
          } catch (err) {
            if (err.code == "9302") {
              // 排队
              await sleep(1500);
              return this.resultFun(this.key);
            } else {
              throw err;
            }
          }
        }
    //此处调用轮询函数
    const orderId = await this.resultFun(res.data.key);
           //调用轮询后需要接受其参数的函数
            const order = await this.wxFunction(orderId);
    

    相关文章

      网友评论

          本文标题:优雅的轮询

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