前端发送并发请求思路

下面试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);
    }
  }
}

猜你喜欢

转载自www.cnblogs.com/liangcheng11/p/9103007.html