[removed] Asynchronous method in while loop

后端 未结 8 2078
一生所求
一生所求 2020-12-15 08:28

I\'m tackling a project that requires me to use JavaScript with an API method call. I\'m a Java programmer who has never done web development before so I\'m having some trou

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 08:52

      let taskPool = new Promise(function(resolve, reject) {
        resolve("Success!");
      });
      let that = this;
      while (index < this.totalPieces) {
        end = start + thisPartSize;
        if (end > filesize) {
          end = filesize;
          thisPartSize = filesize - start;
        }
        taskPool.then(() => {
          that.worker(start, end, index, thisPartSize);
        });
        index++;
        start = end;
      }
    

提交回复
热议问题