Asynchronous method in while loop 构造异步调用链
Asynchronous method in while loop
https://stackoverflow.com/questions/43064719/javascript-asynchronous-method-in-while-loop
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;
}