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;
}

 

posted @ 2019-12-19 19:58  papering  阅读(374)  评论(0编辑  收藏  举报