前端发送并发请求思路

Posted liangcheng11

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了前端发送并发请求思路相关的知识,希望对你有一定的参考价值。

下面试ts简单写的思路代码

enum Statu {
  plain,
  plianing,
  error,
  ready,
}
// 并发数
class Parallel {
  num;
  files = [] as any[];
  PARALLEL_NUM = 0;
  async filesErrorTips () {
    // doto
  }
  async send (index: number) {
    if (!this.files[index]) return;

    if (this.files[index].Statu !== Statu.plianing) {
      this.send(++index);
      return;
    }

    if (this.files[index].Size > ‘500M‘) {
      await this.filesErrorTips();
      this.send(++index);
      return;
    }
    
    const res = await this.fetchApi(); 
    // 错误判断
    this.send(++index);
  }
  fetchApi () {
    // todo
  }
  init () {
    for (let i; i < this.PARALLEL_NUM; i++) {
      this.send(i);
    }
  }
}

以上是关于前端发送并发请求思路的主要内容,如果未能解决你的问题,请参考以下文章