前端发送并发请求思路


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM