前端發送並發請求思路


下面試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